I am getting this sql error in my delete_function:
Invalid query: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 'INSERT INTO cart_order_archive.cart_inventory_.2010_06_19-10-52-29 SELEC' at line 1
CREATE TABLE cart_order_archive.cart_inventory_.2010_06_19-10-52-29 INSERT INTO cart_order_archive.cart_inventory_.2010_06_19-10-52-29 SELECT * FROM cart_order.cart_inventory
I am trying to make a copy of the table before I do the delete.
It stops on the line creating the archive table, more specifically the SELEC...
I added the database name on INSERT INTO instead of using mysql_select_db()
because that sql uses both the cart_order and the cart_order_archive databases. I didn't know which one to use in the mysql_select_db for that query.
Does the SELECT FROM cart_order.cart_inventory need to be on a separate
$sql.= SELECT from ... line?
thanks,
function delete_cart($cart_id, $bu) {
$time= date('Y_m_d-H-i-s');
$sql="SELECT count(*) AS cnt FROM cart_inventory ";
$sql.="WHERE cart_id='$cart_id' AND bu='$bu' ";
mysql_select_db("cart_order");
$result=mysql_query($sql);
echo "<!--\n$sql\n-->";
if ( !$result ) {die("<font color='red'>Invalid query:</font>" . mysql_error() . "<br />$sql");}
$dbarray = mysql_fetch_array($result);
if ( $dbarray['cnt']>0 ){
$sql="CREATE TABLE cart_order_archive.`cart_inventory_.$time` ";
$sql.="INSERT INTO cart_order_archive.`cart_inventory_.$time` SELECT * FROM cart_order.cart_inventory ";
$result=mysql_query($sql);
echo "<!--\n$sql\n-->";
if ( !$result ) die("<font color='red'>Invalid query:</font>" . mysql_error() . "<br />$sql");
$sql="DELETE FROM cart_inventory WHERE cart_id ='$cart_id' AND bu= '$bu' ";
mysql_select_db("cart_order");
$mysql_query($sql);
$result=mysql_query($sql);
echo '<pre>' ;
print_r($result);
echo '</pre>' ;
if ( !$result ) die("<font color='red'>Invalid query:</font>" . mysql_error() . "<br />$sql");
echo "The cart_id: $cart_id and bu:$bu has been deleted</b>";
}
}