CadJoe Posted August 26, 2017 Share Posted August 26, 2017 (edited) 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 Edited August 26, 2017 by CadJoe Quote Link to comment https://forums.phpfreaks.com/topic/304715-fatal-error-call-to-a-member-function-bind_param-on-boolean/ Share on other sites More sharing options...
Solution CadJoe Posted August 26, 2017 Author Solution Share Posted August 26, 2017 (edited) 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 Edited August 26, 2017 by CadJoe Quote Link to comment https://forums.phpfreaks.com/topic/304715-fatal-error-call-to-a-member-function-bind_param-on-boolean/#findComment-1550202 Share on other sites More sharing options...
EasyCoder Posted February 27, 2020 Share Posted February 27, 2020 (edited) You are a star CadJoe! 🐵 This "Call to a member function bind_param() on boolean" error message was driving me crazy, the more that I didn't have any boolean in bind_param values, so didn't understand what this was all about. As you are saying, adding the IF statement to catch the errors is a true life-saver - I saw my problem straigt away - I have mismatched a field name (query vs table). Thanks a lot, you helped me 3 years later! 🐵 EasyCoder Edited February 27, 2020 by EasyCoder Quote Link to comment https://forums.phpfreaks.com/topic/304715-fatal-error-call-to-a-member-function-bind_param-on-boolean/#findComment-1574938 Share on other sites More sharing options...
gizmola Posted February 27, 2020 Share Posted February 27, 2020 The original query would have worked if the proper mysql column name delimiter was used. For column or table names, you delimit them using the backtic character, not the single or double quotes. Wrong: $SQL_INSERT = "INSERT INTO 'Answers' ('QuestionID', 'PlayerID', 'Answer', 'Option') VALUES (?,?,?,?)"; Right $SQL_INSERT = "INSERT INTO `Answers` (`QuestionID`, `PlayerID`, `Answer`, `Option`) VALUES (?,?,?,?)"; Of course you do not need to delimit table or column names in most cases, but there are cases where you must delimit them, in particular if the name is a mysql keyword. Example: CREATE TABLE USER_LIST (id INTEGER UNSIGNED, CURRENT_USER varchar(40)); This won't work, because CURRENT_USER is a MySQL keyword. This works: CREATE TABLE USER_LIST (id INTEGER UNSIGNED, `CURRENT_USER` varchar(40)); Quote Link to comment https://forums.phpfreaks.com/topic/304715-fatal-error-call-to-a-member-function-bind_param-on-boolean/#findComment-1574941 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.