CadJoe
-
Posts
2 -
Joined
-
Last visited
Posts posted by CadJoe
-
-
2 9 0 1
Fatal error: Call to a member function bind_param() on boolean.
It fails on the BIND_PARAM line.
I have looked at this all day, struggling with Mysqli as my normal MySql works fine with assoc and fetch.
I have verified in PhpInfo that mysqli is enabled.
I have verified its loaded using <?php print_r(get_loaded_extensions());
Added utf8 just to make sure.
If I manually use the Wrong Password, I get a connection refused error, so I know its connected.
Verified my $_POST variables are there using Print in the 2 9 0 1 above.
All Table and Field Names are correct. Manual Insert works fine in myPhpAdmin.
Tried Field Names and ? marks with and without single quotes.
All fields are Integers in the table.
Could it be related to an Auto_Increment Field in the table for a record ID that I am not providing??
A normal insert in myPhpAdmin doesn't need it.
$QuestionID = $_POST['qID'];
$PlayerID = $_POST['pID'];
$Answer = $_POST['ans'];
$Option = $_POST['opt'];
print $QuestionID . " ";
print $PlayerID . " ";
print $Answer . " ";
print $Option . " ";
$database = "Survey";
$db_found = new mysqli('localhost', 'survey', 'survey', $database);
$db_found->set_charset("utf8");
if (!$db_found) {
echo "Error: db connection = false";
}
else {
$SQL_INSERT = "INSERT INTO 'Answers' ('QuestionID', 'PlayerID', 'Answer', 'Option') VALUES (?,?,?,?)";
$stmt = $db_found->prepare($SQL_INSERT);
$stmt->bind_param('iiii', $QuestionID, $PlayerID, $Answer, $Option);
$stmt->execute();
}Thanks,
CadJoe
Fatal error: Call to a member function bind_param() on boolean
in PHP Coding Help
Posted · Edited by CadJoe
ok, I have it working now.
Knew it was something with the SQL statement, but couldn't figure out what.
I added this to the top <?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
I changed the Prepare statement to include the error which lead me to error 1064.
Took the single quotes off of the Field Names, and it started working.
Adding the below IF statement is HUGE to see the errors.
$database = "Survey";
$db_found = new mysqli('localhost', 'survey', 'survey', $database);
$db_found->set_charset("utf8");
if (!$db_found) {
echo "Error: db connection = false";
}
else {
$SQL_INSERT = "INSERT INTO Answers (QuestionID, PlayerID, Answer, Option) VALUES (?,?,?,?)";
$stmt = $db_found->prepare($SQL_INSERT);
if($stmt = $db_found->prepare($SQL_INSERT)) {
$stmt->bind_param('iiii', $QuestionID, $PlayerID, $Answer, $Option);
$stmt->execute();
$voteMessage = "Thanks for voting";
} else {
$error = $db_found->errno . ' ' . $db_found->error;
echo $error;
}
} // else
Really hope this HELPS someone else, as I didn't see this anywhere except one link out of hundreds.
Thanks,
CadJoe