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
cturner
Forum Contributor
Posts: 153 Joined: Sun Jul 16, 2006 3:03 am
Location: My computer
Post
by cturner » Tue Jul 18, 2006 1:34 am
I have the following code and I don't know why it is happening:
Parse error: parse error, unexpected T_STRING in /home/blu6592/public_html/diary2/modify_entry.php on line 4
Here is my code that I am working with:
Code: Select all
require "config.php";
$query = 'UPDATE diary_contents SET diary_entry = '$_POST['diary_entry']'';
if (mysql_query ($query)) {
print '<p>The diary entry has been modified. <a href=view.php>Click here</a> to continue.</p>';
} else {
print "<p>Could not add the entry because: <b>" . mysql_error() .
"</b>. The query was $query.</p>";
}
mysql_close();
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Tue Jul 18, 2006 1:37 am
You're not escaping your quotes.
Code: Select all
$query = 'UPDATE diary_contents SET diary_entry = '$_POST['diary_entry']'';
Should be
Code: Select all
$query = 'UPDATE diary_contents SET diary_entry = \'' . $_POST['diary_entry'] . '\'';
daedalus__
DevNet Resident
Posts: 1925 Joined: Thu Feb 09, 2006 4:52 pm
Post
by daedalus__ » Tue Jul 18, 2006 1:37 am
It's happening because you have an unexpected T_STRING.
You are missing the string concatenator:
Code: Select all
require "config.php";
$query = 'UPDATE diary_contents SET diary_entry = ' . $_POST['diary_entry'] . '';
if (mysql_query ($query)) {
print '<p>The diary entry has been modified. <a href=view.php>Click here</a> to continue.</p>';
} else {
print "<p>Could not add the entry because: <b>" . mysql_error() .
"</b>. The query was $query.</p>";
}
mysql_close();
Last edited by
daedalus__ on Tue Jul 18, 2006 1:37 am, edited 1 time in total.
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Tue Jul 18, 2006 1:38 am
Daed,
1) Haha, I beat you to it.
2) bbCode formatting doesn't work inside of code or php tags.
daedalus__
DevNet Resident
Posts: 1925 Joined: Thu Feb 09, 2006 4:52 pm
Post
by daedalus__ » Tue Jul 18, 2006 1:39 am
It looks like you aren't escaping your post data either, you should probably
Code: Select all
mysql_real_escape_string($_POST['diary_entry'])
cturner
Forum Contributor
Posts: 153 Joined: Sun Jul 16, 2006 3:03 am
Location: My computer
Post
by cturner » Tue Jul 18, 2006 1:41 am
Thanks. Problem is now solved.