Page 1 of 1
unexpected T_VARIABLE error
Posted: Sun Aug 02, 2009 8:05 pm
by jeremyhowell
I am having a problem with this code, I have just started using PHP yesterday, and I am getting this error when this code is executed (it is run from another page that has the three fields, title, price, and descrip. Everything works fine 'cept the part that writes to a file):
Code: Select all
<html>
<head>
<title>You have created an auction</title>
</head>
<body>
Congratulations on creating the auction <?php echo $_POST["title"]; ?>!<br />
To view your auction, goto <a href="http://fencingwaikato.co.nz/auction.html">here</a>.
<?php
$title=$_POST["title"]
$price=$_POST["price"]
$descrip=$_POST["descrip"]
$file=fopen("auction.html","w");
fwrite($file,"<html>");
fwrite($file,"<title>" . $title . "</title>");
fwrite($file,"<body>");
fwrite($file,"The price of this item is: " . $price . ".");
fwrite($file,"Description: " . $descrip);
fwrite($file,"</body>");
fwrite($file,"</html>");
?>
</body>
</html>
Re: unexpected T_VARIABLE error
Posted: Sun Aug 02, 2009 8:35 pm
by Jonah Bron
As far as I can see, this code is error-less. Are you sure the problem is not in one of the other files?
Re: unexpected T_VARIABLE error
Posted: Sun Aug 02, 2009 8:40 pm
by jeremyhowell
The only other code is this:
Code: Select all
<html>
<body>
<form action="create.php" method="post">
Title: <input type="text" name="title" />
Price: <input type="text" name="price" />
Description: <input type="textarea" name="descrip">
<input type="submit" />
</form>
</body>
</html>
create.php is the code I posted before.
~ Jeremy
Re: unexpected T_VARIABLE error
Posted: Sun Aug 02, 2009 8:42 pm
by jeremyhowell
This is the error I get:
Parse error: syntax error, unexpected T_VARIABLE in /home/fencingw/public_html/create.php on line 13
Couldn't figure out which one is line 13, does the count start at the top of the page, or from the <?php tag?
~ Jeremy
Re: unexpected T_VARIABLE error
Posted: Sun Aug 02, 2009 9:01 pm
by Eran
the count start at the top of the php file.
the error on line 13 actually refers to the previous line, which does not end with a semicolon. Each instruction line in PHP must end with a semi-colon, and you have about 3 lines missing those.
Re: unexpected T_VARIABLE error
Posted: Sun Aug 02, 2009 9:09 pm
by jeremyhowell
Thanks mate, I got that part working, and it displays the text "Congratulations" etc, but under it is all this:
Warning: fopen(auction.html) [function.fopen]: failed to open stream: Permission denied in /home/fencingw/public_html/create.php on line 16
Warning: fwrite(): supplied argument is not a valid stream resource in /home/fencingw/public_html/create.php on line 17
Warning: fwrite(): supplied argument is not a valid stream resource in /home/fencingw/public_html/create.php on line 18
Warning: fwrite(): supplied argument is not a valid stream resource in /home/fencingw/public_html/create.php on line 19
Warning: fwrite(): supplied argument is not a valid stream resource in /home/fencingw/public_html/create.php on line 20
Warning: fwrite(): supplied argument is not a valid stream resource in /home/fencingw/public_html/create.php on line 21
Warning: fwrite(): supplied argument is not a valid stream resource in /home/fencingw/public_html/create.php on line 22
Warning: fwrite(): supplied argument is not a valid stream resource in /home/fencingw/public_html/create.php on line 23
Warning: fclose(): supplied argument is not a valid stream resource in /home/fencingw/public_html/create.php on line 25
???
~ Jeremy
Re: unexpected T_VARIABLE error
Posted: Sun Aug 02, 2009 9:21 pm
by Eran
take a look at the error messages, they contain the information you need:
failed to open stream: Permission denied in ...
The directory you are trying to open does not have sufficient permissions.
Warning: fwrite(): supplied argument is not a valid stream resource
Since the fopen() call failed, the resulting variable is not a valid stream resource. You should probably add a condition to test if it is a valid resource before proceeding to use fwrite().
You can get more information via the manual -
fopen(),
fwrite()