prashant prashant - 3 months ago 4x
PHP Question

how to update table after inserting in another table in php

here is my php file...
i want to update first table after successful insertion in second table,i am to select and insert properly but the row which i want to update is not getting updated after the data is inserted.


$sql = "SELECT * FROM activations WHERE code='$code' AND status='not used'";
$check = mysqli_fetch_array(mysqli_query($conn,$sql));
echo 'exist';
$sql1="INSERT INTO students(full_name, email_address, contact_number, gender, location, standard, institute) VALUES('$full_name','$email_address','$contact_number','$gender','$location','$standard','$institute')";
if (mysqli_query($conn, $sql1)==true)
$sql2="UPDATE activations SET status='in use' WHERE code='$code';

} else {
echo "Error updating record: " . mysqli_error($conn);

can any one tell me how to write this in php mysqli procedural way.


You forgot to call mysqli_query() to perform the UPDATE.

if (mysqli_query($conn, $sql1)) {
    $sql2="UPDATE activations SET status='in use' WHERE code='$code'";
    if (!mysqli_query($conn, $sql2)) {
        echo "Error updating activations: " . mysqli_error($conn);
} else {
    echo "Error inserting student: " . mysqli_error($conn);