unexpected T_VARIABLE error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jeremyhowell
Forum Newbie
Posts: 4
Joined: Sun Aug 02, 2009 8:01 pm

unexpected T_VARIABLE error

Post 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>
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: unexpected T_VARIABLE error

Post 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?
jeremyhowell
Forum Newbie
Posts: 4
Joined: Sun Aug 02, 2009 8:01 pm

Re: unexpected T_VARIABLE error

Post 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
jeremyhowell
Forum Newbie
Posts: 4
Joined: Sun Aug 02, 2009 8:01 pm

Re: unexpected T_VARIABLE error

Post 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
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: unexpected T_VARIABLE error

Post 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.
jeremyhowell
Forum Newbie
Posts: 4
Joined: Sun Aug 02, 2009 8:01 pm

Re: unexpected T_VARIABLE error

Post 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
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: unexpected T_VARIABLE error

Post 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()
Post Reply