I need your help please with the following code. I'm trying to insert into two tables at the same time, in one table I'm only inserting one line and in the other one I need to insert many rows.
This is the code:
Code: Select all
<?php $con=mysql_connect("host","username","password");
if (!$con)
{
die('La conexion no fue posible: ' .mysql_error());
}
mysql_select_db("databasename",$con);
$sql="INSERT INTO table1 (id_tour, descrip_tour, fecha, guia) VALUES ('$_POST[id_tour]','$_POST[descrip_tour]','$_POST[fecha]','$_POST[guia]')";
echo "<pre>";
print_r($_POST['tour']);
echo "</pre>";
for($i = 0; $i < count($_POST['id_tour']); $i++)
{
$sql = "INSERT INTO table2 (id_tour, idioma, habitacion, cliente, voucher) VALUES ('$_POST[id_tour[$i]]','$_POST[idioma[$i]]','$_POST[habitacion[$i]]','$_POST[cliente[$i]],'$_POST[voucher[$i]])";
echo $sql;
}
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record grabado";
mysql_close($con)
?>