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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.