Forum Moderators: coopster

Message Too Old, No Replies

unexpected T VARIABLE,

         

Binaries2

10:25 am on May 2, 2008 (gmt 0)

10+ Year Member



I'm new to PHP and i've run into a few problems along the way with this script but i have been able to figure most of it out except this one.

Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' in /home/binaries/public_html/pages/addnews.php on line 16

I know that its this piece of code as i have removed it and it runs correctly (i'm not sure how to use string, variables and php code inside of a echo statement, if anyone can explain it to me or link me that would be great.

Code:


echo '<form action='$_SERVER[PHP_SELF]' method="post">
<p><b>News Title :</b><br />
<input type="input" name="title" size="25" maxlength="60" value='if(isset($_POST[title])) echo $_POST[title]' /></p>
<p><b>Name :</b><br />
<input type="input" name="name" size="15" maxlength="35" value='if(isset($_POST[name])) echo $_POST[name]' /></p>
<p><b>Message :</b><br />
<textarea rows="7" cols="55" name="message">'if(isset($_POST["message"])) echo $_POST["message"]'</textarea></p>
<p><input type="submit" name="submit" value="Add News" /></p>
<input type="hidden" name="submitted" value="TRUE" /></p>
</form>';

The first line is line 16.

bilenkyj

10:47 am on May 2, 2008 (gmt 0)

10+ Year Member



you seems to have a nice html php mix here, you need to make sure that html code and php code is defined correctly

where you have an echo used the <?php and ?> tags to close it off from the html

<form action='<?php $_SERVER[PHP_SELF]'?> method="post">
<p><b>News Title :</b><br />
<input type="input" name="title" size="25" maxlength="60" value="<?php if(isset($_POST[title])){echo $_POST[title];}?></p>"
<p><b>Name :</b><br />
<input type="input" name="name" size="15" maxlength="35" value="<?php if(isset($_POST[name])){echo $_POST[name];}?></p>
<p><b>Message :</b><br />
<textarea rows="7" cols="55" name="message"> <?php if(isset($_POST["message"])){echo $_POST["message"];}?></textarea></p>
<p><input type="submit" name="submit" value="Add News" /></p>
<input type="hidden" name="submitted" value="TRUE" /></p>
</form>';

or something similar..........

Binaries2

10:59 am on May 2, 2008 (gmt 0)

10+ Year Member



Thanks for the info, the only problem now is the actual input boxes now have the php code displaying in it instead of executing and displaying the result.

Example:
News Title : Has:

<?php if(isset($_POST[title])) echo $_POST[title]; ?>
in the box along with the other two, Name and Message.

How would this be fixed?

bilenkyj

11:43 am on May 2, 2008 (gmt 0)

10+ Year Member



you need

value="<?php if(isset($_POST[title])){echo $_POST[title];}"
i think the if statment brackets are required

Binaries2

12:10 pm on May 2, 2008 (gmt 0)

10+ Year Member



I had no luck with that... any more ideas? Thanks.

bilenkyj

12:31 pm on May 2, 2008 (gmt 0)

10+ Year Member



value="<?php if(isset($_POST['title'])){echo $_POST['title'];}?>"

try that one

Binaries2

12:33 pm on May 2, 2008 (gmt 0)

10+ Year Member



Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /--/---/---- on line 18

bilenkyj

1:53 pm on May 2, 2008 (gmt 0)

10+ Year Member



<form action="<?php $_SERVER[PHP_SELF];?>" method="post">
<p><b>News Title :</b><br>
<input type="input" name="title" size="25" maxlength="60" value="<?php if(isset($_POST[title])){echo $_POST[title];}?>"</p>
<p><b>Name :</b><br />
<input type="input" name="name" size="15" maxlength="35" value="<?php if(isset($_POST[name])){echo $_POST[name];}?>"</p>
<p><b>Message :</b><br />
<textarea rows="7" cols="55" name="message"><?php if(isset($_POST["message"])){echo $_POST["message"];}?></textarea></p>
<p><input type="submit" name="submit" value="Add News" /></p>
<input type="hidden" name="submitted" value="TRUE" /></p>
</form>

this works, but what are you trying to do anyways?

Pico_Train

2:12 pm on May 2, 2008 (gmt 0)

10+ Year Member



Try this, just a few small changes...close your inputs and use '' in your indeces.

<form action="<?php echo $_SERVER[PHP_SELF];?>" method="post">
<p><b>News Title :</b><br>
<input type="input" name="title" size="25" maxlength="60" value="<?php if(isset($_POST['title'])){echo $_POST['title'];}?>"></p>
<p><b>Name :</b><br />
<input type="input" name="name" size="15" maxlength="35" value="<?php if(isset($_POST['name'])){echo $_POST['name'];}?>"></p>
<p><b>Message :</b><br />
<textarea rows="7" cols="55" name="message"><?php if(isset($_POST['message'])){echo $_POST['message'];}?></textarea></p>
<p><input type="submit" name="submit" value="Add News" /></p>
<input type="hidden" name="submitted" value="TRUE" /></p>
</form>

Binaries2

3:04 pm on May 2, 2008 (gmt 0)

10+ Year Member



Well when echo'ing an input it seems to ignore all php inside of it.

bilenkyj

3:17 pm on May 2, 2008 (gmt 0)

10+ Year Member



how do you mean?
all the script will do is show the input of the form when submitted in their original fields
are you saying that the fields are blank when you submit the form despite inputting info?

Pico_Train

7:13 pm on May 3, 2008 (gmt 0)

10+ Year Member



Yes, please specify what you mean, that above should work fine. it should be blank on first load, fill in the form and submit, the form should then have your $_POST variables in the relevant fields as you had typed them in.

Pico_Train

7:16 pm on May 3, 2008 (gmt 0)

10+ Year Member



<input type="input" should probably be <input type="text"