passing variables threw query

Reply

Join Date: Jun 2005
Posts: 44
Reputation: namit is an unknown quantity at this point 
Solved Threads: 0
namit namit is offline Offline
Light Poster

passing variables threw query

 
0
  #1
Dec 29th, 2005
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
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 107
Reputation: madmital is an unknown quantity at this point 
Solved Threads: 3
madmital madmital is offline Offline
Junior Poster

Re: passing variables threw query

 
0
  #2
Jan 7th, 2006
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........
Web Developer
When something seems too good to be true...it usually is
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 44
Reputation: Ooble is an unknown quantity at this point 
Solved Threads: 6
Ooble's Avatar
Ooble Ooble is offline Offline
Light Poster

Re: passing variables threw query

 
0
  #3
Jan 8th, 2006
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.
  1. while(sleeping)
  2. cat_wails();
  3. wake_up();
  4. for(i=0;i<9;i++)
  5. shoot_cat();
  6. rejoice();
  7. goto(bed);
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for MySQL
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC