Lassie Posted August 17, 2007 Share Posted August 17, 2007 i ahve a form which records into 2 tables property and ads. the update to the ads table produces 2 records not 1. I cant fathom why. Can anyone help please. The query is 'INSERT INTO ads' half way down. if ($rc && $rn && $tp && $un && $ft && $ow && $cl && $oc && $bk && $av && $p && $o && $t && $d) { //If everything OK $v=$_SESSION['user_id']; //add the property $query = "INSERT INTO property (v_id,rci_ref,resort_name,unit_desc,unit_num,floor_type,ownership,floating, occ_wk,booked,available,price,offers,trustees,description) VALUES ($v,$rc,'$rn','$tp','$un','$ft','$ow','$cl','$oc','$bk','$av','$p','$o','$t','$d')"; $result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error()); if (mysql_affected_rows() == 1) { // If it ran OK. //log the advertisement //get last property_id $property_id = mysql_insert_id(); //This causes 2 records to be added to ads $query = "INSERT INTO ads VALUES ('','$u',NOW(),'','','$property_id')"; $result = mysql_query ($query) or die(mysql_error()); $result = mysql_query($query); if (!$result) { echo "Your Property could not be registered due to a system error.Please contact admin@homeownersdirect"; exit(); } //if it ran ok //update property record with ad ref $ad_ref = mysql_insert_id(); $query = "UPDATE property SET ad_ref ='$ad_ref' WHERE property_id = '$property_id'"; $result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error()); $result = mysql_query($query); if (!$result) { echo "Your Property could not be registered due to a system error.Please contact admin@homeownersdirect"; exit(); } Link to comment https://forums.phpfreaks.com/topic/65449-query-inserts-2-records/ Share on other sites More sharing options...
l3asturd Posted August 17, 2007 Share Posted August 17, 2007 Are you calling the INSERT query twice here? $result = mysql_query ($query) or die(mysql_error()); $result = mysql_query($query); If not, add some echo statements before and after the insert to help troubleshoot. Link to comment https://forums.phpfreaks.com/topic/65449-query-inserts-2-records/#findComment-326828 Share on other sites More sharing options...
Lassie Posted August 17, 2007 Author Share Posted August 17, 2007 Many thanks. Thats the problem. I couldn't see the woods for the trees. Cheers Link to comment https://forums.phpfreaks.com/topic/65449-query-inserts-2-records/#findComment-326837 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.