Unexpected T_STRING

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
User avatar
cturner
Forum Contributor
Posts: 153
Joined: Sun Jul 16, 2006 3:03 am
Location: My computer

Unexpected T_STRING

Post by cturner »

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();
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

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'] . '\'';
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Post by daedalus__ »

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.
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Post by daedalus__ »

argh you beat me!
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Daed,

1) Haha, I beat you to it.
2) bbCode formatting doesn't work inside of code or php tags.
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Post by daedalus__ »

It looks like you aren't escaping your post data either, you should probably

Code: Select all

mysql_real_escape_string($_POST['diary_entry'])
User avatar
cturner
Forum Contributor
Posts: 153
Joined: Sun Jul 16, 2006 3:03 am
Location: My computer

Post by cturner »

Thanks. Problem is now solved.
Post Reply