I'm struggeling with a problem and maybe someone could help me :)
in the first query I want to sent data to the first table which generates a id for me, at the second quary I want to retrieve that id made by the first quary, on the 3th quary I want to use that id to insert other data in a second table with the same id as the first table.
My question is this: everything is getting inserted fine except the $id, am I missing something?
<?php
session_start();
//declaratie sessie variabelen
$username = $_SESSION['username'];
$voornaam = $_SESSION['voornaam'];
$achternaam = $_SESSION['achternaam'];
$firma = $_SESSION['firma'];
//database configuratie file
require('dbconfig.php');
//Declaratie post variabelen
$ticnaam = $_POST['ticket_naam'];
$ticonderwerp = $_POST['ticket_onderwerp'];
$ticassign = $_POST['ticket_voor'];
$bericht = $_POST['bericht'];
//proccesing
//procces first quary
$sql = "INSERT INTO `tickets`
(`naam`, `onderwerp`, `maker`)
VALUES ('$ticnaam', '$ticonderwerp', '$username')";
//retrieves the generated new id from the quary above
$sql2 = "SELECT id FROM tickets where onderwerp='$ticonderwerp' AND naam = '$ticnaam';";
$result2 = mysqli_query($mysqli,$sql2);
$id = mysqli_fetch_array($result2,MYSQLI_ASSOC);
//insertes the id into another quary
$sql3 = "INSERT INTO `berichten`
(`id`, `text`, `voornaam`,`achternaam`,`firma`)
VALUES ('$id', '$bericht', '$voornaam',
'$achternaam','$firma')";
//sql3 ok? user can continu
if($mysqli->query($sql3) == TRUE) {
require('email_na_ticketaanmaak.php')
?>
<script>alert('nieuw ticket is gemaakt');</script>
<?php
require('../procces_files/email_na_ticketaanmaak.php');
header('Location: ../home/index.php');
}else{
echo "Error: " . $sql . "<br>" . $mysqli->error;
}
$mysqli->close();
?>