I am attempting to insert some data via prepared statements in PHP. I have the following code which is not inserting for me. I also have the following code set already
ini_set('display_errors', 1);
error_reporting(~0);
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
try {
$sqlInsert = "INSERT INTO deck_cards (deckid, cardid, qty) VALUES (?,?,?)";
$stmtInsert = $conn->prepare($sqlInsert);
if ($stmtInsert)
{
$stmtInsert->bind_param("sss", $deckid, $cardid, $cardcount) or trigger_error($stmtInsert->error, E_USER_ERROR);
$stmtInsert->execute() or trigger_error($stmtInsert->error, E_USER_ERROR);
echo "Check if this ran";
}
else {
echo "Error: " . $sql . "<br>" . $conn->error;
$conn->close();
}
$stmtInsert->close();
}
catch (Exception $ex)
{
echo 'Exception occurred '.$ex->getTraceAsString();
}
When this executes, I do see the text "Check if this ran" but no other messages. The data is not inserted into the database. Additionally, I echo'd the SQL string and variables and ran it against the MySQL directly and it inserted OK. Not sure what is happening in my very straightforward code above.
Additionally, inserts are happening OK in other pages within my app, but this page for some reason isn't working.
I know it's overkill on my error reporting, but I threw everything I could think of to see if there is an error somewhere, but this one is a head scratcher for me. Thanks for any assistance!
" . $conn->error; } – Wil Jan 11 '23 at 16:31