Jump to content

Please help with query


lingo5

Recommended Posts

Hi,

I have 2 queries to insert stuff into 2 tables like so:

 

$idpropiedad=$_POST["id_propiedad"]; //this is a hidden field on my form. Don't know if this is right
$regimen=$_POST["regimen"];
$localidad=$_POST["localidad"];
$isla=$_POST["isla"];
$tipopropiedad=$_POST["tipopropiedad"];
$zona=$_POST["zona"];
$amueblado=$_POST["amueblado"];
$habitaciones=$_POST["habitaciones"];
$estado=$_POST["estado"];
$baños=$_POST["baños"];
$cocina=$_POST["cocina"];
$salon=$_POST["salon"];
$terraza=$_POST["terraza"];
$aseos=$_POST["aseos"];
$metros=$_POST["metros"];
$descripcion=$_POST["descripcion"];
$precio=$_POST["precio"];
$precio_oferta=($_POST['precio_oferta']) ? GetSQLValueString($_POST['precio_oferta']) : "`precio_oferta`";
$novedad=$_POST["novedad"];
$destacada=$_POST["destacada"];

$query = "INSERT INTO midatabase.t_propiedades (id_propiedad,regimen, localidad, isla, tipopropiedad, zona, amueblado, habitaciones, estado, baños, cocina, salon, terraza, aseos, metros, descripcion, precio, precio_oferta, novedad, destacada)".
"VALUES ('$idpropiedad', '$regimen', '$localidad','$isla','$tipopropiedad', '$zona','$amueblado','$habitaciones','$estado','$baños','$cocina','$salon','$terraza','$aseos','$metros','$descripcion','$precio','$precio_oferta','$novedad','$destacada')";

mysql_query($query) or die('Error, query failed : ' . mysql_error());

$query2 ="INSERT INTO midatabase.t_imagenes(id_propiedad,imagen_path)".
"VALUES ('$idpropiedad','$filePath')";

mysql_query($query2) or die('Error, query failed : ' . mysql_error());

 

My problem is that I need the id_propiedad inserted in the first table to get also inserted in the second one....but all I get in the second one is "0".

How can I insert the same id_property into both tables?

 

Thanks

Link to comment
Share on other sites

Thanks wigwambam, but that's not what I'm after.

 

id_propiedad on table 1 is the primary key and auto increment and is inserted automatically when a new property is created.

 

id_propiedad on table 2 gets set to 0 and it should be the same value of id_propiedad on table 1

 

Thanks

Link to comment
Share on other sites

I don't understand your logic. If id_propiedad on table 1 is the primary key and auto increment why are you passing it in your form data?

 

You should insert the record without the id and let the database generate the next one for you.

 

Change this line:

$query = "INSERT INTO midatabase.t_propiedades (id_propiedad,regimen, localidad, isla, tipopropiedad, zona, amueblado, habitaciones, estado, baños, cocina, salon, terraza, aseos, metros, descripcion, precio, precio_oferta, novedad, destacada)".
"VALUES ('$idpropiedad', '$regimen', '$localidad','$isla','$tipopropiedad', '$zona','$amueblado','$habitaciones','$estado','$baños','$cocina','$salon','$terraza','$aseos','$metros','$descripcion','$precio','$precio_oferta','$novedad','$destacada')";

 

To:

$query = "INSERT INTO midatabase.t_propiedades (regimen, localidad, isla, tipopropiedad, zona, amueblado, habitaciones, estado, baños, cocina, salon, terraza, aseos, metros, descripcion, precio, precio_oferta, novedad, destacada)".
"VALUES ('$regimen', '$localidad','$isla','$tipopropiedad', '$zona','$amueblado','$habitaciones','$estado','$baños','$cocina','$salon','$terraza','$aseos','$metros','$descripcion','$precio','$precio_oferta','$novedad','$destacada')";

 

AND stick the other code in I mentioned earlier.

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.