Hello, I am trying to update 3 tables that i have in my db. the second and third INSERT commands there is a specific field that needs to have the ID of the first table last row inserted.
first table, admin:
+--------------------+
|id username passcode|
|1 admin test |
+--------------------+
second table custcomp
+--------------------+
|id cid cpuname sn |
|1 1 test test |
+--------------------+
third table computerdb
+--------------------+
|id cid cpid ticket |
|1 1 1 123456 |
+--------------------+
Now the CID needs to be the same in all fields which is the id(auto_increment) of the user in admin.
The CPID needs to be the id(auto_increment) of custcomp table
In my code i have $con->insert_id which works for the first one, but the CPID
Here is my input codes:
$con = mysqli_connect("localhost","ROOT","ROOT","MY_DB");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL:" . mysqli_connect_error();
}
$query = "INSERT INTO admin(name, email, phone, username, passcode, access_level) VALUES ('".$_POST['name']."','".$_POST['email']."','".$_POST['phone']."','".$username."','".$db_password."', '1')";
if (!mysqli_query($con,$query))
{
die('Error: ' . mysqli_error($con));
}else{
$sql2 = "INSERT INTO custcomp (cid, cpuname, sn, model, brand, hdd, memory, type )
VALUES ('".$con->insert_id."','Pending Update','N/A', 'Pending Update', 'Pending Update', 'Pending Update', 'Pending Update', 'Pending Update')";
if (!mysqli_query($con,$sql2))
{
die('Error: ' . mysqli_error($con));
}else{
$sql = "INSERT INTO computerdb (cpid, cid, ticket, computerpass, status, notes )
VALUES ('".$con->insert_id."','".$con->insert_id."','".$_POST['ticketnumber']."','".$_POST['password']."', 'Pending', '".date('m/d/Y H:i:s'). ": Work has started on your computer')";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}else{
//more code to email info:
I think I might have gotten in over my head on this...
any help or ideas would be great!