[PHP] opendir() Question

2009-06-12 Thread Parham Doustdar
Hi there,
I need to create a PHP script that will connect to an  FTP, get a listing of 
files/directories from it, and displays them in a table. Now, there is only one 
problem here.
I tried connecting with opendir(), like this:
opendir("ftp://...";);
but it seems it doesn't work with FTP. Now, is there another thing I could use 
for the same effect?
Thanks!
-- 
---
Contact info:
Skype: parham-d
MSN: fire_lizard16 at hotmail dot com
email: parham90 at GMail dot com

Re: [PHP] opendir() Question

2009-06-12 Thread Parham Doustdar
Hello there Andrew,
Thank you very much for your help. I didn't know such an extention existed. 
:)

-- 
---
Contact info:
Skype: parham-d
MSN: fire_lizard16 at hotmail dot com
email: parham90 at GMail dot com
"Andrew Ballard"  wrote in message 
news:b6023aa40906121312m47034863k9c502e07d66c4...@mail.gmail.com...
2009/6/12 Parham Doustdar :
> Hi there,
> I need to create a PHP script that will connect to an FTP, get a listing 
> of files/directories from it, and displays them in a table. Now, there is 
> only one problem here.
> I tried connecting with opendir(), like this:
> opendir("ftp://...";);
> but it seems it doesn't work with FTP. Now, is there another thing I could 
> use for the same effect?
> Thanks!
> --
> ---
> Contact info:
> Skype: parham-d
> MSN: fire_lizard16 at hotmail dot com
> email: parham90 at GMail dot com

RTM http://www.php.net/ftp

Andrew 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Periodic Actions in PHP?

2009-06-13 Thread Parham Doustdar
Hi there,
I'm going to create a small chat script with PHP. The messages you want others 
to see will be added to a flat file (I.E. TXT file), and read and displayed by 
PHP. However, I want this reading and displaying to be periodic. This means 
that I want PHP to check the file for new lines every,say, fifteen seconds. How 
may I do that? I have been unable to find any function that acts like a timer.
Thanks!
-- 
---
Contact info:
Skype: parham-d
MSN: fire_lizard16 at hotmail dot com
email: parham90 at GMail dot com

Re: [PHP] Periodic Actions in PHP?

2009-06-14 Thread Parham Doustdar
Actually, your message sparked an idea in my [slow] mind. :)
I can put the PHP code in a java script, and tell javascript to call it 
every fifteen seconds. Best option, I think. :)
Any ideas?
Thanks!
-- 
---
Contact info:
Skype: parham-d
MSN: fire_lizard16 at hotmail dot com
email: parham90 at GMail dot com
""bruce""  wrote in message 
news:1528701c9ec4d$322e6cb0$0301a...@tmesa.com...
> hi...
>
> is this a php/web based app...
> are the users using the chat function via the browser..
> if this is a browser/web app, are you looking for a way for the
> php web app to refetch the textfile... i would assume so...
>
> have you figured out a rough architecture/design for your app..
> in your design, you're going to need to figure out how to
> accomplish updates to the text file, and when you do, you'll
> also have figured out how to do the reads...
>
> i'm assuming that you don't want a continuously running thread
> for your php/web app.. ie one continuously, never ending loop...
> -so you'll have the user add some text, the app will write this to
>  a file..
> the user will either select a refresh kind of btn, or your
> app will have to implement a refresh process, which will then
> fetch new/updated data from your files..
> etc...
>
>
>
>
>
>
> -Original Message-
> From: richard.he...@gmail.com [mailto:richard.he...@gmail.com]on Behalf
> Of Richard Heyes
> Sent: Saturday, June 13, 2009 2:17 AM
> To: Parham Doustdar
> Cc: php-general@lists.php.net
> Subject: Re: [PHP] Periodic Actions in PHP?
>
>
> Hi,
>
>> I'm going to create a small chat script with PHP. The messages you want
> others to see
>> will be added to a flat file (I.E. TXT file), and read and displayed by
> PHP. However, I want
>> this reading and displaying to be periodic. This means that I want PHP to
> check the file for
>> new lines every,say, fifteen seconds. How may I do that? I have been
> unable to find any
>> function that acts like a timer.
>
> If you're on Unix then look into using cron. Type the following at the
> command prompt to get info on cron:
>
> man 5 crontab
>
> Cron tasks can be scheduled at most once per minute. And if you're
> using Windows then I believe the equivalent would be task scheduler,
> but I've no idea how you would go about using it.
>
> --
> Richard Heyes
> HTML5 graphing: RGraph (www.rgraph.net - updated 6th June)
> PHP mail: RMail (www.phpguru.org/rmail)
> PHP datagrid: RGrid (www.phpguru.org/rgrid)
> PHP Template: RTemplate (www.phpguru.org/rtemplate)
> PHP SMTP: http://www.phpguru.org/smtp
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Deleting a file after download/upload

2009-06-23 Thread Parham Doustdar
Hi there,
I am writing a PHP FTP client for my project. I want to put a "download" option 
and an "upload"" option, but I don't know how. My problem is this:
How can I make the server the PHP script is on delete the file after uploading 
it to the SFTP, or after the user has finished downloading it from the server 
the PHP script is on?
Let me put the question this way.
My server connects to an FTP. Then, it downloads a file from the FTP, and then 
sends me the link to that temperary file on the server. Now, when I download it 
from my server, my script should delete the file. How can I make it wait until 
the download of the file is finished?
Same goes for uploading.
Thanks!

-- 
---
Contact info:
Skype: parham-d
MSN: fire_lizard16 at hotmail dot com
email: parham90 at GMail dot com

[PHP] Re: Deleting a file after download/upload

2009-06-25 Thread Parham Doustdar
Hi there Shawn,
Thank you for your help. That works.

-- 
---
Contact info:
Skype: parham-d
MSN: fire_lizard16 at hotmail dot com
email: parham90 at GMail dot com
"Shawn McKenzie"  wrote in message 
news:ee.3d.36467.c0261...@pb1.pair.com...
> Parham Doustdar wrote:
>> Hi there,
>> I am writing a PHP FTP client for my project. I want to put a "download" 
>> option and an "upload"" option, but I don't know how. My problem is this:
>> How can I make the server the PHP script is on delete the file after 
>> uploading it to the SFTP, or after the user has finished downloading it 
>> from the server the PHP script is on?
>> Let me put the question this way.
>> My server connects to an FTP. Then, it downloads a file from the FTP, and 
>> then sends me the link to that temperary file on the server. Now, when I 
>> download it from my server, my script should delete the file. How can I 
>> make it wait until the download of the file is finished?
>> Same goes for uploading.
>> Thanks!
>>
>
> Well if you write a download script, then you can delete it at the end
> and it won't be deleted until after the download completes:
>
> //Do your ftp from remote to local'/path/to/file.ext'
> exec('ftp_get.sh remotefile.ext /path/to/file.ext);
> //or
> $conn_id = ftp_connect($ftp_server);
> $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
> ftp_gett($conn_id, '/path/to/file.ext', $server_file, FTP_BINARY)
> ftp_close($conn_id);
>
>  //send proper headers for download
> readfile('/path/to/file.ext');
>
> unlink('/path/to/file.ext');
> ?>
>
> For upload, depending upon how you're doing it, a call to unlink()
> shouldn't execute until your FTP is done and exited:
>
>  //User uploads file to '/path/to/file.ext'
>
> exec('ftp_put.sh /path/to/file.ext);
> //or
> $conn_id = ftp_connect($ftp_server);
> $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
> ftp_put($conn_id, $server_file, '/path/to/file.ext', FTP_BINARY)
> ftp_close($conn_id);
>
> unlink('/path/to/file.ext');
> ?>
>
> -- 
> Thanks!
> -Shawn
> http://www.spidean.com 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] PHP Raw-listing Problem

2009-07-01 Thread Parham Doustdar
Hi there everyone,
First of all, let me thank you for your always-present help in this list; I (as 
a newbie) appreciate it very much! :)
However, pardon me for I need to trouble you with another piece of text that 
doesn't do what it should do:
I need to parse the raw-listing of an FTP into it's parts (the code comes from 
the book published by Wrox, however, I don't have the book in my posession to 
check the two versions against each other), but it returns an empty list. Here 
is the code:
[code]
switch ($this->systype){ //Parse raw dir listing into fields
 case 'Windows_NT':  //Handle WinNT FTP servers
 $re = '/^.' .
 '([0-9-]+\s+)'.   //Get last mod date
 '\d\d:\d\d..)\s+' .  //Get last mod time
 '(\S+)\s+' .//Get size or dir info
 '(.+)$/';//Get file/dir name
 break;
 
 case 'UNIX':   //Handle UNIX FTP servers
 default://case UNIX falls through to default
  $re = '/'.   //Regax to parse common server dir into
  '^(.)' .   //Get entry type info (file/dir/etc.)
  '(\S+)\s+' .   //Get permissions info
  '\S+\s+'.   //Find, but don't capture hard link info
  '(\S+)\s+' .  //Get owner name
  '(\S+)\s+' .  //Get group name
  '(\S+)\s+' .  //Get size
  '(\S+\s+\S+\s+\S+\s+)' . //Get file/dir last mod time
  '(.+)$/';   //Get file/dir name
  break;
 }
 
 //Map short identifiers to full names
 $type = array('-'=>'file','d'=>'directory');
 
 $listing = array();
 
 foreach ($temp as $entry) {  //loop through raw listings
 //try to parse raw data into fields
 $match=preg_match($re,$entry,$matches);
 
  if(!$match) {   //if we could not parse the listings
  user_error("The directory listings could not be parsed.");
  return array();   
  }
 
 switch ($this->systypes){  //Give fileds sensible names
 case 'Windows_NT';//Handle WinNT-style dir listings
  $listings[] = array( //Put parsed data into readable format
  'type' =>
is_numeric($matches[2]) ? 'file' : 'directory','permissions' => 
null,'owner' =>NULL,'group'=>null,'size'=>(int)$matches[2],
'last mod' => $matches[1],'name'=>$matches[3]);
 break;
 
 case 'UNIX':  //Handle UNIX FTP-style dir listings
 default:   //case UNIX fails through to default
 $strings[] = array( //Put data into readable format
 'type' =>$type[$matches[1]],'permissions' => $matches[2],'owner' 
=>$matches[3],'group' => $matches[4],'size' => $matches[5],
 'last mod' =>$matches[6],'name'=>$matches[7]);
 break;
  
 }
 } 
  return $listings;
[/code]

Since this function is called Is($directory); I tried this:
var_dump($ftp_server->Is($ftp_server->cwd));

However, I get null.

Why?

(It's not that I understand how the raw-listing is being parsed using regular 
expressions, so it's why I'm asking :) )

Thanks!
-- 
---
Contact info:
Skype: parham-d
MSN: fire_lizard16 at hotmail dot com
email: parham90 at GMail dot com

[PHP] Problem: Writing into Files?

2009-07-31 Thread Parham Doustdar
Hi there,
I've written a counter for my blog, which keeps the count of visitors in a 
file. However, when the visitors get too many, it resets to zero. Why?

Here's the piece of code:

[code]
$f = $dir . '/view_counter' .EXT;
$fp = fopen($f, "r");
$count =fgets($fp, 1024);
fclose($fp);
$fw = fopen($f, "w");
$cnew = $count + 1;
$countnew = fputs($fw, $count + 1);
return $cnew;
[/code]

I'm thinking this is caused by two visitors visiting the page at the same time; 
but is there a way to fix it, perhaps the reading/writing parameter?

Thanks!

-- 
---
Contact info:
Skype: parham-d
MSN: fire_lizard16 at hotmail dot com
email: parham90 at GMail dot com

[PHP] Re: Problem: Writing into Files?

2009-08-01 Thread Parham Doustdar
Dear Ollisso,
I tried it with FLock() but it still didn't work. This is what I did:
[code]
$fp = fopen($f, "r");
$count =fgets($fp, 1024);
fclose($fp);
$fw = fopen($f, "w");
while (!flock($fw, LOCK_EX))
sleep(1);
$cnew = $count + 1;
$countnew = fputs($fw, $count + 1);
flock($fw, LOCK_UN);
fclose($fw);
[/code]

Am I doing anything wrong here?
Thanks!
-- 
---
Contact info:
Skype: parham-d
MSN: fire_lizard16 at hotmail dot com
email: parham90 at GMail dot com
"Ollisso"  wrote in message 
news:op.uxy29woc48v...@ol-n.kyla.fi...
> On Sat, 01 Aug 2009 08:20:23 +0300, "Parham Doustdar"  
> wrote:
>
>> Hi there,
>> I've written a counter for my blog, which keeps the count of visitors in 
>> a file. However, when the visitors get too many, it resets to zero. Why?
>>
>> Here's the piece of code:
>>
>> [code]
>> $f = $dir . '/view_counter' .EXT;
>> $fp = fopen($f, "r");
>> $count =fgets($fp, 1024);
>> fclose($fp);
>> $fw = fopen($f, "w");
>> $cnew = $count + 1;
>> $countnew = fputs($fw, $count + 1);
>> return $cnew;
>> [/code]
>>
>> I'm thinking this is caused by two visitors visiting the page at the 
>> same time; but is there a way to fix it, perhaps the reading/writing 
>> parameter?
>>
>> Thanks!
>>
>
> Check:
> http://www.php.net/flock
>
>
> -- 
> Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Problem: Writing into Files?

2009-08-02 Thread Parham Doustdar
Now this one always sets the file to one for some reason. I'll reiterate 
just in case there's been a misunderstanding on my part:
[code]
$fp = fopen($f, "r+");
while (!flock($fp, LOCK_EX))
sleep(1);
$count = fgets($fp,filesize($fp));
ftruncate($fp, 0);
fwrite($fp, ($count+1));
flock($fp, LOCK_UN);
fclose($fp);
Thanks a lot again for your help.
-- 
---
Contact info:
Skype: parham-d
MSN: fire_lizard16 at hotmail dot com
email: parham90 at GMail dot com
"Ollisso"  wrote in message 
news:op.ux03zprl48v...@ol-n.kyla.fi...
> On Sun, 02 Aug 2009 07:11:27 +0300, "Parham Doustdar"  
> wrote:
>
>> Dear Ollisso,
>> I tried it with FLock() but it still didn't work. This is what I did:
>> [code]
>> $fp = fopen($f, "r");
>> $count =fgets($fp, 1024);
>> fclose($fp);
>> $fw = fopen($f, "w");
>> while (!flock($fw, LOCK_EX))
>> sleep(1);
>> $cnew = $count + 1;
>> $countnew = fputs($fw, $count + 1);
>> flock($fw, LOCK_UN);
>> fclose($fw);
>> [/code]
>>
>> Am I doing anything wrong here?
>> Thanks!
> Hello,
>
> Actually you should do something like this (according to manual)
>
> $f=fopen("file", "r+");
> while(!flock($f, LOCK_EX)) sleep(1);
> $count = fgets($f,1024);
> ftruncate($f, 0);
> fwrite($f, $count+1);
> fclose($f);
>
> Problem in your case: first time you open file for reading, but you don't 
> flock it, so it can read non-writen file.
>
>
>
>
> -- 
> Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Problem: Writing into Files?

2009-08-02 Thread Parham Doustdar
Dear Richard,
I don't quite know how I can write a bite into a file. I also looked into a 
manual and couldn't find a mention of FLock-ing in the explaination for 
FOpen parameters.
Thanks a lot for your help.

-- 
---
Contact info:
Skype: parham-d
MSN: fire_lizard16 at hotmail dot com
email: parham90 at GMail dot com
"Richard Heyes"  wrote in message 
news:af8726440908020221r22e1efb3g321ba4140bfa4...@mail.gmail.com...
> Hi,
>
>> ...
>
> You can write a single byte to the file to "increment" the counter,
> then to read the count just use filesize(). I believe the a fopen()
> mode will handle locking for you. It will result in a slowly growing
> file, but space isn't exactly at a premium nowadays, and when the file
> gets to a certain size (eg 1 gazillion k) you could use a summary
> file.
>
> -- 
> Richard Heyes
> HTML5 graphing: RGraph - www.rgraph.net (updated 25th July)
> Lots of PHP and Javascript code - http://www.phpguru.org 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset not functioning

2009-08-03 Thread Parham Doustdar
Your if-statement should be like this:

[code]
if(isset($_REQUEST['firstname']) && !empty($_REQUEST['firstname'])) {
...
}
[/code]
-- 
---
Contact info:
Skype: parham-d
MSN: fire_lizard16 at hotmail dot com
email: parham90 at GMail dot com
"Allen McCabe"  wrote in message 
news:657acef20908031008nc2c29cdo3e13733bc6f29...@mail.gmail.com...
>I created a simple survey for my work website, most of the PHP is on my
> process.php document, which is referenced by a form on a seperate page
> containing the form with the method of "post".
>
> On my process.php page, the script obtains the field data using the
> $_REQUEST[] function.
>
> I have a small if statement to check to see if they filled out the
> 'firstname' field, and if they did not, to replace $name with "Sir or
> Madam". Unfortunately, $name always equals "Sir or Madam", wether a value
> for "firstname" was entered or not.
>
> All the of the other instances of using $_REQUEST[] functions just fine, 
> but
> don't make use of if or isset. Here is the code snippet:
>
> if(isset($_REQUEST['firstname']) && !empty($RESULT['firstname'])) {
> $name = $_REQUEST['firstname'];
> } else {
> $name = 'Sir or Madam';
> }
>
> I also tried adding an underscore to $RESULT (I got the code for this from 
> a
> php.net comment on the manual), to make it $_RESULT, but this doesn't seem
> to be a pre-set function, and it still does not make it work. I am 
> guessing
> the user neglected to define $RESULT in his snippet, or I overlooked it.
>
> Can anyone see any problems with the code?
> 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Question: what are frameworks?

2009-08-09 Thread Parham Doustdar
Hi there,
I've heard of frameworks, but I don't quite know what they are used for. I've 
done a little search on the internet, but even though I've been able to find 
different PHP frameworks, I'm not quite sure what they offer, or in what they 
differ, or why I shouldn't just use PHP as it is.
Can someone give a little bit of explaination?
Thanks!

-- 
---
Contact info:
Skype: parham-d
MSN: fire_lizard16 at hotmail dot com
email: parham90 at GMail dot com

[PHP] Question: Sorting through table headers?

2009-09-13 Thread Parham Doustdar
Hello there,
I've been asked to create something like the tables you usually see, where the 
headers are actually links and when you click the links, the table gets sorted 
based on the header. Are there any classes that you know of that would do the 
job? My current idea is to return an array of the colomn which contains the 
data you want to sort on (like 'name') then sort the array and do something 
like:
[code]
for (i = 0; i < length(array); i++)
mysql_query("select * from table where 'name' = ${aray[i]}");
[/code]
Any better algorithms anyone?
Thanks!
-- 
---
Contact info:
Skype: parham-d
MSN: fire_lizard16 at hotmail dot com
GoogleTalk: parha...@gmail.com
Twitter: PD90
email: parham90 at GMail dot com

Re: [PHP] Question: Sorting through table headers?

2009-09-17 Thread Parham Doustdar
Hello there,
Thanks a lot. The Javascript class worked like a charm. I'm glad I asked! :)
Thanks for all the answers, everyone. I seem to have communicated my intent 
wrong, when it came to my algorithm, but basically, yes, it was not based on 
the MVC model, and yes, it did filter the SQL table, then sorted them and 
displayed each row according to the ID, for example, of the different things 
in the SQL table. In other words, let's say that I wanted to get the ID, 
sort the array containing the ID's, then show the rows of the table by 
looping through the array and showing each row of the table.
However, the javascript did what I wanted perfectly anyway. I have to read 
up more on Javascript since I seem to have an awful understanding of it, but 
for now... *phew* hehe!

-- 
---
Contact info:
Skype: parham-d
MSN: fire_lizard16 at hotmail dot com
GoogleTalk: parha...@gmail.com
Twitter: PD90
email: parham90 at GMail dot com
"Jim Lucas"  wrote in message 
news:4aadec1e.60...@cmsws.com...
> Parham Doustdar wrote:
>> Hello there,
>> I've been asked to create something like the tables you usually see, 
>> where the headers are actually links and when you click the links, the 
>> table gets sorted based on the header. Are there any classes that you 
>> know of that would do the job? My current idea is to return an array of 
>> the colomn which contains the data you want to sort on (like 'name') then 
>> sort the array and do something like:
>> [code]
>> for (i = 0; i < length(array); i++)
>> mysql_query("select * from table where 'name' = ${aray[i]}");
>> [/code]
>> Any better algorithms anyone?
>> Thanks!
>
> My suggestion would be to have the client do it.
>
> http://www.js-vault.us/iscripts/007.html
>
> I use it on a number of different pages.
> -- 
> Jim Lucas
>
>"Some men are born to greatness, some achieve greatness,
>and some have greatness thrust upon them."
>
> Twelfth Night, Act II, Scene V
> by William Shakespeare 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Question: Correcting MySQL's ID colomn when removing an entry

2009-09-20 Thread Parham Doustdar
Hello there,
I'm guessing that when a row in a MySQL table is removed, the ID colomns of the 
rows which come after that row are not changed. For example:
1
2
3
4

Now, if I want to remove the third rows, the ID colomn would be something like:
1
2
4

I was wondering if there was a way to fix it through a query, so I wouldn't 
have to use a for statement in PHP to fix it?

Thanks!

-- 
---
Contact info:
Skype: parham-d
MSN: fire_lizard16 at hotmail dot com
GoogleTalk: parha...@gmail.com
Twitter: PD90
email: parham90 at GMail dot com

[PHP] Question: Wai-aria?

2009-09-22 Thread Parham Doustdar
Hello there,
I have asked on the mailing lists that have blind users and no one seems to 
know about this technology (that is ironically created to help us blind folks). 
I was wondering if anyone here has the experience of implementing Wai-aria. 
Since my question is rather about Wai-aria than PHP and is off-topic, I'm first 
of all sorry to be posting it here (it is rather an act of desperation). 
Secondly, I ask people who have the time to help me to please contact me 
off-list at parham90 at gmail dot com.
Thanks.
-- 
---
Contact info:
Skype: parham-d
MSN: fire_lizard16 at hotmail dot com
GoogleTalk: parha...@gmail.com
Twitter: PD90
email: parham90 at GMail dot com

[PHP] Strange MySQL Problem

2009-12-14 Thread Parham Doustdar
Hello there,
Here's a short PHP script a friend has written, and given to me to test.
However, I am getting a MySQL error saying that the syntax error, on the
line that contains mysql_connect(); is wrong, near '')'
(note that it is not a PHP error, but a MySQL error.)
Here's the code:

[code]

[/code]




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Strange MySQL Problem

2009-12-14 Thread Parham Doustdar
Hi there,
Does it differ? I thought when in quotations, variables like that would be 
automatically interpreted?
Also, the MySQL is meant to connect to localhost. I had emptied it for 
testing purposes. With or without it, I get the same error.
"Jochen Schultz"  wrote in message 
news:4b25fb8e.3040...@sportimport.de...
> Hello Parham,
>
> i think you should change this:
>
> $sql = "INSERT INTO BOOK(bookname, authorsname, ISBN) VALUES
>  ('$_POST[bookname]', '$_POST[authorsname]', $_POST[ISBN]')";
>
> to this:
>
> $sql = "INSERT INTO BOOK(bookname, authorsname, ISBN) VALUES
> ('".$_POST[bookname]."', '".$_POST[authorsname]."', '".$_POST[ISBN]."')";
>
>
> best regards
> Jochen
>
>
> Parham Doustdar schrieb:
>> Hello there,
>> Here's a short PHP script a friend has written, and given to me to test.
>> However, I am getting a MySQL error saying that the syntax error, on the
>> line that contains mysql_connect(); is wrong, near '')'
>> (note that it is not a PHP error, but a MySQL error.)
>> Here's the code:
>>
>> [code]
>> > $username = "root";
>> $password = "abc";
>> $con = mysql_connect("", $username, $password);
>> mysql_select_db ("test", $con);
>> $sql = "INSERT INTO BOOK(bookname, authorsname, ISBN) VALUES
>> ('$_POST[bookname]', '$_POST[authorsname]', $_POST[ISBN]')";
>> if (!mysql_query($sql, $con))
>>  {
>> die( 'error: ' . mysql_error());
>>   }
>> echo "1 record added";
>> mysql_close($con)
>> ?>
>> [/code]
>>
>>
>> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Strange MySQL Problem

2009-12-14 Thread Parham Doustdar
Thank you, everyone. All fixed.
"metastable"  wrote in message 
news:4b260641.80...@metastable-services.net...
> Parham Doustdar wrote:
>> Hi there,
>> Does it differ? I thought when in quotations, variables like that would 
>> be
>> automatically interpreted?
>> Also, the MySQL is meant to connect to localhost. I had emptied it for
>> testing purposes. With or without it, I get the same error.
>> "Jochen Schultz"  wrote in message
>> news:4b25fb8e.3040...@sportimport.de...
>>
>>> Hello Parham,
>>>
>>> i think you should change this:
>>>
>>> $sql = "INSERT INTO BOOK(bookname, authorsname, ISBN) VALUES
>>>  ('$_POST[bookname]', '$_POST[authorsname]', $_POST[ISBN]')";
>>>
>>> to this:
>>>
>>> $sql = "INSERT INTO BOOK(bookname, authorsname, ISBN) VALUES
>>> ('".$_POST[bookname]."', '".$_POST[authorsname]."', 
>>> '".$_POST[ISBN]."')";
>>>
>>>
>>> best regards
>>> Jochen
>>>
>>>
>>> Parham Doustdar schrieb:
>>>
>>>> Hello there,
>>>> Here's a short PHP script a friend has written, and given to me to 
>>>> test.
>>>> However, I am getting a MySQL error saying that the syntax error, on 
>>>> the
>>>> line that contains mysql_connect(); is wrong, near '')'
>>>> (note that it is not a PHP error, but a MySQL error.)
>>>> Here's the code:
>>>>
>>>> [code]
>>>> >>> $username = "root";
>>>> $password = "abc";
>>>> $con = mysql_connect("", $username, $password);
>>>> mysql_select_db ("test", $con);
>>>> $sql = "INSERT INTO BOOK(bookname, authorsname, ISBN) VALUES
>>>> ('$_POST[bookname]', '$_POST[authorsname]', $_POST[ISBN]')";
>>>> if (!mysql_query($sql, $con))
>>>>  {
>>>> die( 'error: ' . mysql_error());
>>>>   }
>>>> echo "1 record added";
>>>> mysql_close($con)
>>>> ?>
>>>> [/code]
>>>>
>>>>
>>>>
>>>>
>>
>>
>>
> Exactly the opposite. Use double quotes for interpolation.
> Moreover, you would still get an error, as mysql requires text columns
> to be escaped. Use Jochens code.
> Also: SQL injection ! --> http://en.wikipedia.org/wiki/SQL_injection
>
>
> HTH,
>
> Stijn 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Streaming OGG/MP3

2010-01-04 Thread Parham Doustdar

Hello there,
I wonder how I can stream MP3/OGG files with PHP? I'm running UniServer 
on a Windows machine, if that helps.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] MySQL ID -- what happens when you run out of range?

2010-01-25 Thread Parham Doustdar
Hello there,
A friend called me today and was wondering what happens if the ID colomn of 
an MYSQL database, set to autoinc reaches the int limit. Will it return and 
begin choosing the ID's that have been deleted, or... what?
Thanks! 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] MySQL query not working!

2010-03-31 Thread Parham Doustdar
Hi there,
Here is a snippet of code... that doesn't work for some reason. Please note 
that I have put some

@mysql_query($query) or die(mysql_error());

statements, to see if MySQL gives an error. I receive nothing other than the 
file starting to download. This is supposed to be a file download counter:

[code]
http://www.qwitter-client.net/' . $_GET['file']);
}
else //it's the first time we're adding this file to the DB.
{
$query = "insert into " . $table . " (filename, hits) values ('" . 
$_GET['file'] . "', 1)";
@mysql_query($query) or die(mysql_error());
header('location:http://www.qwitter-client.net/' . $_GET['file']);
}
?> 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] MySQL query not working!

2010-03-31 Thread Parham Doustdar

Andre,
The @ operator is used for error catching statements. When you put:

@mysql_connect('localhost', 'username', 'password') or die('Could not 
connect.');


If PHP fails to make a connection, the script execution is stopped, and the 
error message between the apostrophes is given.


And, I found out what the problem was; I should have put:

if (mysql_num_rows($result))

rather than just

if ($result)

Thanks!
- Original Message - 
From: "Andre Polykanine" 

To: "Parham Doustdar" 
Cc: 
Sent: Wednesday, March 31, 2010 4:41 PM
Subject: Re: [PHP] MySQL query not working!



Hello Parham,

Adding to Ash's question, why to use the @ operator before
mysql_query?
--
With best regards from Ukraine,
Andre
Skype: Francophile; Wlm&MSN: arthaelon @ yandex.ru; Jabber: arthaelon @ 
jabber.org

Yahoo! messenger: andre.polykanine; ICQ: 191749952
Twitter: m_elensule

- Original message -
From: Parham Doustdar 
To: php-general@lists.php.net 
Date: Wednesday, March 31, 2010, 2:50:07 PM
Subject: [PHP] MySQL query not working!

Hi there,
Here is a snippet of code... that doesn't work for some reason. Please 
note

that I have put some

@mysql_query($query) or die(mysql_error());

statements, to see if MySQL gives an error. I receive nothing other than 
the

file starting to download. This is supposed to be a file download counter:

[code]
$query = "select * from " . $table . " where filename = '" . $_GET['file'] 
.

"'";
$result = mysql_query($query);

if ($result) //Has the file previously been added?
{
$query = "update " . $table . " set hits = hits + 1 where filename = '" .
$_GET['file'] . "'";
@mysql_query($query) or die(mysql_error());
header('location:http://www.qwitter-client.net/' . $_GET['file']);
}
else //it's the first time we're adding this file to the DB.
{
$query = "insert into " . $table . " (filename, hits) values ('" .
$_GET['file'] . "', 1)";
@mysql_query($query) or die(mysql_error());
header('location:http://www.qwitter-client.net/' . $_GET['file']);
}
?>



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Question: Farsi characters showing as jibberish

2010-04-24 Thread Parham Doustdar
Hi,

I have created a PHP file, and wrote a string of Farsi letters in it. In the 
head section of the HTML, I put:



There appears to be something wrong with Apache, or something, because no 
matter whether I put that string in an echo statement or just in an HTML 
with a php extention, the page loads as jibberish and I have to set the 
character encoding to UTF-8 manually in Firefox.

Renaming that same file to .htm (when not using the echo statement), and 
loading it in the browser shows me the correct Farsi characters.

Should I change something in Apache's settings for this to work?

Thanks! 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Question: Farsi characters showing as jibberish

2010-04-24 Thread Parham Doustdar
Hi Ashley and Michiel,

It appears it is something in Apache or my server program on Windows (I am
using Uniform Server; a portable webserver from
http://www.uniformserver.com). The reason I got to such a conclusion is
this:

1. I uploaded the pHP file to a free hosting website. Here is the URL:
http://blindmoviebuff.uphero.com/test2.php

2. I put the same page in my www folder in Windows. Here's the address to
that:
http://parham-d.dyndns.org/test2.php

As you can see, the page on uphero.com displays without any encoding changes
required by you, whereas the second has to be manual (for some reason). I
thought seeing the UTF-8 made the browser use that encoding automatically
regardless of whether or not it was sent in UTF-8?

Sorry, I have no information at all about how transmiting is handled. Just
saying guesses aloud. :-)
- Original Message - 
From: "Ashley Sheridan" 
Newsgroups: php.general
To: "Michiel Sikma" 
Cc: "Parham Doustdar" ; 
Sent: Saturday, April 24, 2010 6:16 PM
Subject: Re: [PHP] Question: Farsi characters showing as jibberish


> On Sat, 2010-04-24 at 15:38 +0200, Michiel Sikma wrote:
>
>> On 24 April 2010 14:45, Parham Doustdar  wrote:
>>
>> > Hi,
>> >
>> > I have created a PHP file, and wrote a string of Farsi letters in it.
>> > In
>> > the
>> > head section of the HTML, I put:
>> >
>> > 
>> >
>> > There appears to be something wrong with Apache, or something, because
>> > no
>> > matter whether I put that string in an echo statement or just in an
>> > HTML
>> > with a php extention, the page loads as jibberish and I have to set the
>> > character encoding to UTF-8 manually in Firefox.
>> >
>> > Renaming that same file to .htm (when not using the echo statement),
>> > and
>> > loading it in the browser shows me the correct Farsi characters.
>> >
>> > Should I change something in Apache's settings for this to work?
>> >
>> > Thanks!
>> >
>> >
>> > No, that should work perfectly fine. Are you sure that the PHP file
>> > itself
>> is utf-8?
>> Could it be that you manually set the text encoding to something else in
>> your browser, causing it to remember that setting?
>>
>> Perhaps you could link us to the page itself so we can have a look. Note
>> that the best place to put that  tag is right after the opening
>> 
>> tag, before any other header information.
>>
>> Michiel
>
>
> If renaming the file as .htm shows the characters correctly, then
> the .php file is most likely saved as utf8.
>
> Maybe Apache has been instructed to send all HTML with another encoding,
> as it should send it out with the same encoding as the requested PHP
> script.
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Question: Farsi characters showing as jibberish

2010-04-24 Thread Parham Doustdar
Hi again,
That did work, indeed. Now, I guess that means that Apache is outputting the 
PHP as something other than UTF-8. In fact, googling, I came up with this 
line of .htaccess:

AddDefaultCharset UTF-8

which works perfectly!

Thank you, everyone, for yet again helping me out.
"Ashley Sheridan"  wrote in message 
news:1272117941.20937.164.ca...@localhost...
> On Sat, 2010-04-24 at 18:37 +0430, Parham Doustdar wrote:
>
>> Hi Ashley and Michiel,
>>
>> It appears it is something in Apache or my server program on Windows (I 
>> am
>> using Uniform Server; a portable webserver from
>> http://www.uniformserver.com). The reason I got to such a conclusion is
>> this:
>>
>> 1. I uploaded the pHP file to a free hosting website. Here is the URL:
>> http://blindmoviebuff.uphero.com/test2.php
>>
>> 2. I put the same page in my www folder in Windows. Here's the address to
>> that:
>> http://parham-d.dyndns.org/test2.php
>>
>> As you can see, the page on uphero.com displays without any encoding 
>> changes
>> required by you, whereas the second has to be manual (for some reason). I
>> thought seeing the UTF-8 made the browser use that encoding automatically
>> regardless of whether or not it was sent in UTF-8?
>>
>> Sorry, I have no information at all about how transmiting is handled. 
>> Just
>> saying guesses aloud. :-)
>> - Original Message - 
>> From: "Ashley Sheridan" 
>> Newsgroups: php.general
>> To: "Michiel Sikma" 
>> Cc: "Parham Doustdar" ; 
>> Sent: Saturday, April 24, 2010 6:16 PM
>> Subject: Re: [PHP] Question: Farsi characters showing as jibberish
>>
>>
>> > On Sat, 2010-04-24 at 15:38 +0200, Michiel Sikma wrote:
>> >
>> >> On 24 April 2010 14:45, Parham Doustdar  wrote:
>> >>
>> >> > Hi,
>> >> >
>> >> > I have created a PHP file, and wrote a string of Farsi letters in 
>> >> > it.
>> >> > In
>> >> > the
>> >> > head section of the HTML, I put:
>> >> >
>> >> > 
>> >> >
>> >> > There appears to be something wrong with Apache, or something, 
>> >> > because
>> >> > no
>> >> > matter whether I put that string in an echo statement or just in an
>> >> > HTML
>> >> > with a php extention, the page loads as jibberish and I have to set 
>> >> > the
>> >> > character encoding to UTF-8 manually in Firefox.
>> >> >
>> >> > Renaming that same file to .htm (when not using the echo statement),
>> >> > and
>> >> > loading it in the browser shows me the correct Farsi characters.
>> >> >
>> >> > Should I change something in Apache's settings for this to work?
>> >> >
>> >> > Thanks!
>> >> >
>> >> >
>> >> > No, that should work perfectly fine. Are you sure that the PHP file
>> >> > itself
>> >> is utf-8?
>> >> Could it be that you manually set the text encoding to something else 
>> >> in
>> >> your browser, causing it to remember that setting?
>> >>
>> >> Perhaps you could link us to the page itself so we can have a look. 
>> >> Note
>> >> that the best place to put that  tag is right after the opening
>> >> 
>> >> tag, before any other header information.
>> >>
>> >> Michiel
>> >
>> >
>> > If renaming the file as .htm shows the characters correctly, then
>> > the .php file is most likely saved as utf8.
>> >
>> > Maybe Apache has been instructed to send all HTML with another 
>> > encoding,
>> > as it should send it out with the same encoding as the requested PHP
>> > script.
>> >
>> > Thanks,
>> > Ash
>> > http://www.ashleysheridan.co.uk
>> >
>> >
>> >
>>
>>
>>
>
> Try adding this before any output to the browser:
>
> header('Content-Type: text/html; charset=utf-8');
>
> Which should force the server to send the output in this specific
> format.
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
> 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Question: Farsi characters showing as jibberish

2010-04-24 Thread Parham Doustdar
Hi,
It probably did because I added the line,

AddDefaultCharset UTF-8

to my .htaccess a few moments ago. :-)
"Michiel Sikma"  wrote in message 
news:o2p6cda1ded1004240726l272f04fbmdd2fb996e2580...@mail.gmail.com...
> On 24 April 2010 16:07, Parham Doustdar  wrote:
>
>> Hi Ashley and Michiel,
>>
>> It appears it is something in Apache or my server program on Windows (I 
>> am
>> using Uniform Server; a portable webserver from
>> http://www.uniformserver.com). The reason I got to such a conclusion is
>> this:
>>
>> 1. I uploaded the pHP file to a free hosting website. Here is the URL:
>> http://blindmoviebuff.uphero.com/test2.php
>>
>> 2. I put the same page in my www folder in Windows. Here's the address to
>> that:
>> http://parham-d.dyndns.org/test2.php
>>
>> As you can see, the page on uphero.com displays without any encoding
>> changes
>> required by you, whereas the second has to be manual (for some reason).
>
> -snip-
>>
>>
>
> Actually, both of these work fine for me. I don't have to manually set the
> encoding to get the Farsi characters to show up in either of these links.
> I don't know why it wouldn't work for you. Maybe you should try a 
> different
> browser to make sure it isn't a cached setting. Adding the header() call
> that Ashley suggested also seems like a good idea.
>
> Michiel
> 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php