Jump to content

query inserts 2 records


Lassie

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.