So I am trying to send data entered in a single form to multiple tables using multiple queries but it is not working. I have the connection thing working right and this way it works fine for one query but the problem comes when I try to use multiple tables, like getting data and sending it to multiple tables What I have done so far is:
$qry= "INSERT INTO register VALUES (DEFAULT, '".$email."', '".$passw."')";
$qry = "INSERT INTO personalinformation VALUES (DEFAULT, '".$name."',
'".$fname."', '".$age."', '".$gender."', '".$cnic."',
'".$mobileno."','".$address."', '".$appearencestatus."')";
Kindly help. Thank you so much
With PDO you'd do something like:
$stmt = $db->prepare("INSERT INTO register (email, password) VALUES (:email, passw)";
$stmt->execute(array('name' => $name, 'email' => $email))
Once for each query. It's important to always specify the columns you're inserting against, it avoids ambiguity when your schema changes for some reason plus the crufty DEFAULT junk in there.
Try to prepare directly from a string, don't make intermediate variables for this sort of stuff. Those can easily get confused, over-written, and tangled up in your code.
Did you create a database connection? And did you execute the query with mysqli_query ? Try troubleshooting by echoing out the composed query, and copy pasting it in mysql console or in php myadmin.
Here is a sample:
$con = mysqli_connect('hostname', 'username', 'password', 'dbname');
Your queries composition code: Then
mysqli_query($con, $queryvariablename);
--
P.S make sure you use different variable names for different queries or else the second one will overrite the previous one.