Search code examples
phpmysqlcopymove

Error moving data from one table to another


$feedback_list = array( 
    array('date1', '87586cb8b79861edcc4e6a12104b87529c53050375904ff180'), 
    array('date2', 'abc1d08c3e42cffa7eaaa84eb4fe04b44c34be497ce7e8ea26') 
);

foreach($feedback_list as $feedback) {
    $result = mysql_query("INSERT INTO 'inactive_users' (token, username) 
       SELECT (token, username) FROM active_users WHERE token = '$feedback[1]'");
    if (!mysql_query($result,$con)) { die('Error: ' . mysql_error()); }
}

.. echoes the correct value, which is also present in active_users table, but the value is not copied to the second table. Error is:

Error: Query was empty


Solution

  • You're running the mysql_query twice. Try

    foreach($feedback_list as $feedback) {
        $result = "INSERT INTO `inactive_users` (token, username) 
           SELECT token, username FROM active_users WHERE token = '{$feedback[1]}'";
        if (!mysql_query($result,$con)) { die('Error: ' . mysql_error()); }
    }