Reputation: 11
I'm having this MySQL sentence which use an insert and update in the same query:
if(mysql_query('insert into forum_topics (parent, id, id2, title, message, authorid, timestamp, timestamp2) select "'.$dn1['parent'].'", "'.$id.'", max(id2)+1, "", "'.$message.'", "'.$_SESSION['SESS_MEMBER_ID'].'", "'.time().'", "'.time().'" from forum_topics where id="'.$id.'"') and mysqli_query('update forum_topics set timestamp2="'.time().'" where id="'.$id.'" and id2=1'))
Which I tried to convert into mysqli this way:
$qry = 'insert into forum_topics (parent, id, id2, title, message, authorid, timestamp, timestamp2) select "'.$dn1['parent'].'", "'.$id.'", max(id2)+1, "", "'.$message.'", "'.$_SESSION['SESS_MEMBER_ID'].'", "'.time().'", "'.time().'" from forum_topics where id="'.$id.'"';
$qry2 = 'update forum_topics set timestamp2="'.time().'" where id="'.$id.'" and id2=1';
$dn3 = $link -> query($qry AND $qry2);
if (!$dn3)...
Unfortunately, it don't seem to work as I'm being throwed this error:
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 '1' at line 1
Is there anyone who can help with this?
Upvotes: 0
Views: 54
Reputation: 34232
If you want to follow the original logic, then
$dn3 = ($link -> query($qry) AND $link->query($qry2));
Because of the logical and operator in the php code, the 2 query strings were interpreted in a boolean operation BEFORE they were submitted to mysql.
As a result, the value 1 (true) was sent to mysql, which obviously resulted in the syntax error message.
Upvotes: 1