My question is not easy to explain for myself, but I will train.
I can insert a record into a table´s column form a form with php to mysql without problems. This insert generates an auto_increment
record in another column from the same table.
So I want to select this new auto_increment
record and insert
it in another table.
<?php
// process form`enter code here`
$db_host="myhost";
$db_user="myuser";
$db_password="mypassword";
$db_name="mydbname";
$db_table_name="table1";
$db_table_name2="table2";
$record1= utf8_decode($_POST['record1']);
$record2= utf8_decode($_POST['redord2']);
$db_connection = mysqli_connect($db_host,$db_user,$db_password,$db_name);
if (!$db_connection) {
die('Could not connect to the database');
}
//insert record1 into table1
$insert_value = 'INSERT INTO `' . $db_name . '`.`'.$db_table_name.'` (`name`) VALUES ("' . $record1 . '")';
$result1 = $db_connection->query($insert_value);
//consult auto_increment column from table1
$select_value = 'SELECT column FROM table1 WHERE name = "' . $record1 . '"';
//insert record2 into table2 in a row where a column is like $record1
$insert_value2 = 'INSERT INTO `' . $db_name . '`.`'.$db_table_name2.'` (`column1, column2`) VALUES ("' . $record2. '","' . $select_value . '") WHERE name = "'.$db_table_name2.'"';
$result2 = $db_connection->query($select_value);
mysqli_close($db_connection);
?>