Hello. I'm writing script and trying to run a few queries. Unforunately, I've noticed that one query seems to be invalidating another. Here's the code:
<?php
// Extracts array coming from Prelim Info Page
extract ($_POST);
// Declares Primary Key for use in the Insert Query below...
$primaryKey=$userName;
$primaryKey .= "1";
//Connects to database
$user="****";
$host="localhost";
$password="******";
$connection=mysqli_connect($host, $user, $password) or die ("Couldn't connect to MySQL!!");
$database="1003Form";
$db=mysqli_select_db($connection, $database) or die ("Cannot connect to the 1003 Form Database!");
// Query to update Prelim Info Table w. data from Prelim Info page
$query="INSERT INTO preliminfo(userName, primaryKey, transType, propType, resType, loanAmt, estValue, numBorrowers) VALUES ('$userName', '$primaryKey', '$transType', '$propType', '$resType', '$loanAmt', '$estValue', '$numBorrowers')";
$result = mysqli_query($connection, $query) or die ("<center>Couldn't Update Database With Preliminary Info</center>");
// Insert Query here to update all tables for the Borrower (no co-borrowers)
$query= "INSERT INTO assetinfo (userName, primaryKey) VALUES ('$userName', '$primaryKey');
INSERT INTO emplhistory (userName, primaryKey) VALUES ('$userName', '$primaryKey');
INSERT INTO income (userName, primaryKey) VALUES ('$userName', '$primaryKey');
INSERT INTO primarydata (userName, primaryKey) VALUES ('$userName', '$primaryKey');
INSERT INTO reoinfo (userName, primaryKey) VALUES ('$userName', '$primaryKey');
INSERT INTO residencehistory (userName, primaryKey) VALUES ('$userName', '$primaryKey')";
$result = mysqli_multi_query($connection, $query) or die ("Could not update Tables w. UserName and Primary Keys!!!");
echo "$primaryKey";
// New Query to check to see the results of the Insert Query above
$query="SELECT * FROM preliminfo WHERE primaryKey='$primaryKey'";
$result=mysqli_query($connection, $query) or die ("<center>Could not check to see the results of the Preliminary Table update!</center>");
$row=mysqli_fetch_array($result) or die ("Couldn't Fetch Array!");
extract($row);
...add'l script.....yada yada yada....
?>
So there are 3 queries all together. Query #1 has no problems. But Query #2 will execute successfully (I checked the MySQL D😎, only to have the DIE statement execute for Query #3 - "Could not check to see the results of the Preliminary Table Update!".
If I disable (?) Query #2 by putting slashes in front of it, Query #3 works perfectly. So what's happening in Query #2 seems to have an affect on Query #3. I just can't see it.
The echo statement between the two queries is just for my testing purposes and it doesn't affect the query execution because I've tested the queries with it disabled as well.
Any help? 🙁