Hello everybody,
I have a code where I have 2 inserts and a select before the 2 inserts to bring the higher number from my first table and then increment that number to be inserted in both tables. The field where I insert that number is called id_tour, but the select always brings a number 3, so is not working. Can you please help me with this?
This is the code I have:
// connect to the db
$con = mysql_connect ('host', 'username', 'password');
if (!$con)
{
die ('Could not connect: ' .mysql_error());
}
mysql_select_db('myDB', $con);
// HERE IS WHERE I BRING THE VALUE OF THE FIELD id_tour TO HAVE IT INCREMENTED
$sql1 = "SELECT id_tour FROM table";
$contador = mysql_query($sql1)+1;
// HERE IS WHERE I BRING THE VALUE OF THE FIELD id_tour TO HAVE IT INCREMENTED
$descrip_tour = $_POST['descrip_tour'];
$fecha = $_POST['fecha'];
$guia = $_POST['guia'];
if (($descrip_tour !='') && (fecha != '') && ($guia != '')) {
$sql2 = "INSERT INTO table (id_tour, descrip_tour, fecha, guia) VALUES (
'$contador', '$descrip_tour', '$fecha', '$guia')";
$result = mysql_query($sql2);
}
foreach($_POST['records'] as $record) {
$prueba = $contador;
$language = $record['language'];
$room = $record['room'];
$name = $record['name'];
$voucher = $record['voucher'];
if (($language != '') && ($room !='') && (name != '') && ($voucher != '')) {
$sql = "INSERT INTO table (id_tour, language, room, name, voucher) VALUES ( '$prueba', '$language', '$room', '$name', '$voucher')";
$result = mysql_query($sql);
}
echo "1 record added";
}
//EndForEach segment
//echo "1 record added";