944,221 Members | Top Members by Rank

Ad:
  • MySQL Discussion Thread
  • Unsolved
  • Views: 12012
  • MySQL RSS
Dec 29th, 2005
0

passing variables threw query

Expand Post »
Hey all

What is with this query

$query = mysql_query("UPDATE `namitposts` SET `title` = '$topic' , `date` = '$date' ', `postee` = '$postee', `post` = '$post_text' , `ip` = '$ip' WHERE `id` = '$del'") . mysql_error();

Its not passing the variables am getting this error message


Notice: Query error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'postee--', `post` = 'post
--asdfsafasf' , `ip` = '83.70.242 SQL: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'postee--', `post` = 'post
--asdfsafasf' , `ip` = '83.70.242 in /home/namit/public_html/admin/index.php on line 162
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
namit is offline Offline
44 posts
since Jun 2005
Jan 7th, 2006
0

Re: passing variables threw query

Quote originally posted by namit ...
$query = mysql_query("UPDATE `namitposts` SET `title` = '$topic' , `date` = '$date' ', `postee` = '$postee', `post` = '$post_text' , `ip` = '$ip' WHERE `id` = '$del'") . mysql_error();
Needs to be:
$query = mysql_query("UPDATE namitposts SET title = '" . $topic . "', date = '" . $date . "', postee........
Reputation Points: 10
Solved Threads: 5
Junior Poster
madmital is offline Offline
119 posts
since Jun 2005
Jan 8th, 2006
0

Re: passing variables threw query

No... the code is fine... double quotes in PHP tell it to parse the string for variable names and replace as necessary.

Why are you concatenating the mysql_query return value with the mysql_error return value?

Try this:
[php]$sql = "UPDATE `namitposts` SET `title` = '$topic' , `date` = '$date' ', `postee` = '$postee', `post` = '$post_text' , `ip` = '$ip' WHERE `id` = '$del'";
if ($query = mysql_query($sql))
{
// do stuff
}
else
{
echo '<pre>' . $sql . "\n" . mysql_error() . '</pre>';
}[/php]
If it fails, scan the SQL for any errors.
Reputation Points: 12
Solved Threads: 6
Light Poster
Ooble is offline Offline
44 posts
since Oct 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MySQL Forum Timeline: MySql database Synchronization
Next Thread in MySQL Forum Timeline: ERROR 2002: Can't connect to local MySQL server





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC