I'm working on a project but I'm stuck. I'm making a system to change the answer and question of aq quesion from the FAQ-page on a website. For that I use 2 tables in SQL. One who contains the answers and one that contains the question which contains a column for the number of which ID is connected for the answer. Bit I can't run those 2 SQL's in once, can someone help me fix the problem. I need to update my answers-table first to get the ID from the new answer to connect it to the questions-table.
Thanks in advance.
Code for the updates
<?php
include('../inc/connection.php');
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (isset($_POST['fields'])) {
foreach ($_POST['fields'] as $item) {
$values[] = $db->real_escape_string($item);
}
var_dump($values);
if ($stmt = $db->prepare("INSERT INTO AntwoordenFAQ (nl_antwoord,fr_antwoord,en_antwoord) VALUES (?,?,?);")) {
$stmt->bind_param('sss', $values[0], $values[1], $values[2]);
if ($stmt->execute()) {
if ($stmt->affected_rows == 1) {
$IDinsert = $db->insert_id;
if ($stmt = $db->prepare("INSERT INTO VragenFAQ (nl_vraag, fr_vraag, en_vraag) VALUES (?,?,?);")) {
$stmt->bind_param('sss', $values[3], $values[4], $values[5]);
if ($stmt->execute()) {
if ($stmt->affected_rows == 1) {
echo TRUE;
}
else {
echo $IDinsert;
}
}
$stmt->close();
}
}
else {
echo FALSE;
}
}
$stmt->close();
}
$db->close();
}
}
exit();
?>