Click to See Complete Forum and Search --> : Inserting datas in different tables


Perfidus
11-08-2003, 09:38 AM
How can I insert datas in different tables?
I have been trying this dbut didn't worked out...

$sql = "INSERT INTO DatosInmueble ( Tipo, Localidad)" .
"VALUES ('$Tipo', '$Localidad)";
$result = mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>');
$sql2 = "INSERT INTO Precios ( Ref, ene1)".
"VALUES (Ref', '$ene1')";
$result2 = mysql_query($sql2) or die(mysql_error().'<p>'.$sql2.'</p>');
$sql3 = "INSERT INTO Disponibilidad ( Ref, ene1d)".
"VALUES (Ref', '$ene1d, '$ene2d)"
$result3 = mysql_query($sql3) or die(mysql_error().'<p>'.$sql3.'</p>');
echo "¡Gracias! Hemos recibido sus datos.\n";

YoN
11-08-2003, 04:54 PM
You don't have to split it into two strings, anyways if that's the way you like it... there's no space between "INSERT INTO DatosInmueble ( Tipo, Localidad)" and "VALUES ('$Tipo', '$Localidad)" because you concatenated the strings but didn't put any space between them.
Anyways, I'd do it like this:
$sql = "INSERT INTO DatosInmueble (Tipo, Localidad) VALUES ('".$Tipo."', '".$Localidad."')";
$result = mysql_query($sql) or die(mysql_error()."<p>".$sql."</p>");
$sql2 = "INSERT INTO Precios (Ref, ene1) VALUES ('Ref', '".$ene1."')";
$result2 = mysql_query($sql2) or die(mysql_error()."<p>".$sql."</p>");
$sql3 = "INSERT INTO Disponibilidad (Ref, ene1d) VALUES ('Ref', '".$ene1d.", '".$ene2d.")"
$result3 = mysql_query($sql3) or die(mysql_error()."<p>".$sql."</p>");
echo "¡Gracias! Hemos recibido sus datos.\n";HTH.