hey guys, my code copies a record to a history table and then select all the comments for that record and copies them to a history table. now for some odd reason, SOMETIMES the comments arent copied to their history table, and even stranger, when they arent copied, they also arent deleted. call me crazy, i dunno. also, how can i make this code fail-safe or a better way to do it? thanks!
$del_query = mysql_query("SELECT * FROM current_calls WHERE CID='$CID'", $link_id);
$num_rows = mysql_num_rows($del_query);
$del_result = mysql_fetch_row($del_query);
if ($num_rows == 1)
{
$copy_query = mysql_query("INSERT INTO call_his VALUES('$del_result[0]','$del_result[1]','$del_result[2]','$del_result[3]','$del_result[4]','$del_result[5]','$del_result[6]','$del_result[7]','$SID1', NOW() + 0)", $link_id);
$del_query2 = mysql_query("DELETE FROM current_calls WHERE CID='$CID'", $link_id);
$com_query = mysql_query("SELECT * FROM comments_calls WHERE CID='$CID'", $link_id);
while ($com_result = mysql_fetch_row($com_query))
{
$copy_query2 = mysql_query("INSERT INTO comments_calls2 VALUES('$com_result[0]','$com_result[1]','$com_result[2]','$com_result[3]','$com_result[4]','$com_result[5]','$com_result[6]','$com_result[7]','$com_result[8]')", $link_id) OR die(mysql_error());
}
$del_query3 = mysql_query("DELETE FROM comments_calls WHERE CID='$CID'", $link_id);
echo "Record deleted.<br>";
}
else
{
echo "Record not found.<br>";
}