mysql - insert data from one table to another php sql -
i'm making private messages application , trying create 'deleted messages' folder messages user wants delete inbox or sent folder go 'deleted'. managed write code delete them not want. created table in database, named 'deleted' i'm trying delete them inbox , insert them there.
this have until now:
if ( isset($_get['delete'])) { $multiple = $_get['multiple']; $i=0; $q = "insert deleted (select * email to_user = '$user')"; foreach($multiple $msg_id) { $i++; if ($i==1) { $q .= " id = ". mysql_real_escape_string($msg_id).""; } else { $q .= "or id = ". mysql_real_escape_string($msg_id).""; } } mysql_query($q) or die (mysql_error()); header("location: " .$_server['php_self']); exit(); }
it giving me error:
you have error in sql syntax; check manual corresponds mysql server version right syntax use near 'where id = 14' @ line 1
the output of script be:
insert deleted (select * email to_user = '$user') id = 14
you can't have on insert clause. looking is:
insert deleted (select * email to_user = '$user' , id = 14)
which can account adjusting position of closing bracket, , adjusting clause listed , instead.
on further reflection, not accomplish want. attempting join multiple id's together, way , and or in sql work, not accomplish attempting. or statement need wrapped in brackets ensure got caught , statement, so:
insert deleted (select * email to_user = '$user' , (id = 14 or id = 15))
your code should read this:
$q = "insert deleted (select * email to_user = '$user' "; foreach($multiple $msg_id) { $i++; if ($i==1) { $q .= " , (id = ". mysql_real_escape_string($msg_id).""; } else { $q .= " or id = ". mysql_real_escape_string($msg_id).""; } } $q .= "))"; // closing out both brackets
Comments
Post a Comment