Update recordset with prepared statement php not working

Hello Experts,

I have a php script that iterates through the nodes of an xml-file with the use of foreach - succesfully...

It puts all the nodes in variables - succesfully...

With the data for each node stored in a variable I then query the database to see if the data already exists - succesfully...

If the recordset returns empty the variables get inserted in to the database using prepared Insert statement - succesfully

If the recordset returns data the variables will be used to update that entrie in the database - unsuccesfully

What happens next is: There is no update taking place in the database values and the scripts stops doing stuff (looping) after the line bind_param gets called in the update function...

Step 1 inside the foreach -> the variables are made and have data -> succesfully
// The variables
$pid= value;
$isbn = value;
$trigger = value;

Open in new window

Step 2 inside the foreach -> I query the database -> succesfully
$hostname_site_i = "yyy";
$database_site_i = "yyy";
$username_site_i = "yyy";
$password_site_i = "yyy";

	$conn = new mysqli($hostname_site_i, $username_site_i, $password_site_i, $database_site_i);
	// Check connection
	if ($conn->connect_error) {
	    die("Connection failed: " . $conn->connect_error);
	/* Create a prepared statement */
	$stmt = $conn -> prepare("SELECT T_ISBN FROM titels_feed_copy WHERE T_ISBN = ?");
	/* Bind parameters */
	$stmt -> bind_param("s", $trigger);
	/* Execute it */
	$stmt -> execute();
	/* Bind results */
	$stmt -> bind_result($result);
	/* Fetch the value */
	$stmt -> fetch();

Open in new window

Step 3. Now if the recordset is empty I make an insert statement to add the new data - Succesfully
if ($result == 0) {
// insert record
$query = "INSERT INTO titels_feed_copy (T_BiblioId, T_ISBN, T_Titel, T_Status, T_Bindwijze,T_Omslag,T_Uitgeverijid,T_Datum,T_Omvang,T_Prijs,T_ISBN_Ebook,T_Flaptekst,T_Kernzin,T_Promotie, T_AuthorTekst,T_NUR) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
$stmtInsert = $conn->prepare($query);
$stmtInsert->bind_param("isssssdsssssssss", $pid, $isbn, $titel, $statusCode, $bindwijze, $cover, $imprintId, $datum, $pages, $price, $isbnEbook, $flaptekst, $kernzin, $promotietekst,$auteurtekst, $Subject[$SubjectSchemeIdentifier]['SubjectCode']); // i = integer / d = double / s = string / b = blob
$newId = $stmtInsert->insert_id;

Open in new window

Step 4. If the recordset is not empty i try to update that record with update statement -> This is where the scripts comes to a hold
else if ($result > 0) {
		$query = "UPDATE titels_feed_copy SET 'T_BiblioId'=?, 'T_Titel'=? WHERE 'T_ISBN'=?";
		$stmtUpdate = $conn->prepare($query);
		$stmtUpdate->bind_param("iss",$pid,$titel,$isbn); // i = integer / d = double / s = string / b = blob

Open in new window

Up until when the line: $stmtUpdate->bind_param("iss",$pid,$titel,$isbn); // i = integer / d = double / s = string / b = blob everything goes as desired...

After the update statement the connection gets closed and the foreach should start the whole process again...

Can anyone spot what I am doing wrong here in the update function? Sure hope so... Feels like I am really close but can't seem to figure this part out...

The error message that gets thrown is:
Fatal error: Call to a member function bind_param() on boolean in D:\www\domain.com\www\folder\folder2\test.php on line 243

Lin 243 is: $stmtUpdate->bind_param("iss",$pid,$titel,$isbn); // i = integer / d = double / s = string / b = blob

Thank you very much in advance for any comments and suggestions on this matter... If you neer more data/info let me know I will be sure to provide it asap...


Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

WitheetAuthor Commented:
I tried many many things... But what finally did the trick was to add: $stmt->close(); after $stmt -> fetch();

Still not completely sure what caused this... Sugggestions are very welcome!


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.