doubledee Posted October 3, 2011 Share Posted October 3, 2011 My brain isn't working... I am trying to get this Prepared Statement to pull Events from my database and display them, but get this error... Warning: mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt, boolean given in /Users/user1/Documents/DEV/++htdocs/01_MyProject/events_9.php on line 30 Here is my code... <?php // Initialize a session. session_start(); // Access Constants. require_once('config/config.inc.php'); // Initialize variables. $eventExists = FALSE; // Connect to the database. require_once(ROOT . 'private/mysqli_connect.php'); // ******************** // Build Event Query * // ******************** $id=1; // Build query. $q = 'SELECT id, name, location, date FROM show WHERE id=?'; // Prepare statement. $stmt = mysqli_prepare($dbc, $q); // Bind variable. mysqli_stmt_bind_param($stmt, 'i', $id); (The last line above is Line 30.) Debbie Quote Link to comment https://forums.phpfreaks.com/topic/248311-warning-mysqli_stmt_bind_param-expects-parameter-1/ Share on other sites More sharing options...
Buddski Posted October 3, 2011 Share Posted October 3, 2011 The mysqli_prepare function returns a boolean value, hence the error you are receiving; Try mysqli_stmt_bind_param($dbc, 'i', $id); Quote Link to comment https://forums.phpfreaks.com/topic/248311-warning-mysqli_stmt_bind_param-expects-parameter-1/#findComment-1275089 Share on other sites More sharing options...
doubledee Posted October 3, 2011 Author Share Posted October 3, 2011 The mysqli_prepare function returns a boolean value, hence the error you are receiving; Try mysqli_stmt_bind_param($dbc, 'i', $id); I've always had my code the way it was posted here. (I just copied and pasted it from another part of my site that works.) Debbie Quote Link to comment https://forums.phpfreaks.com/topic/248311-warning-mysqli_stmt_bind_param-expects-parameter-1/#findComment-1275090 Share on other sites More sharing options...
Buddski Posted October 3, 2011 Share Posted October 3, 2011 Ok, what variable is mysqli_stmt_init() assigned to? This line $stmt = mysqli_prepare($dbc, $q); says it is stored in $dbc. Quote Link to comment https://forums.phpfreaks.com/topic/248311-warning-mysqli_stmt_bind_param-expects-parameter-1/#findComment-1275092 Share on other sites More sharing options...
PFMaBiSmAd Posted October 3, 2011 Share Posted October 3, 2011 Your prepare is failing due to an error of some kind. A) You always need to use error checking/error reporting logic in your code so that you don't trigger follow-on errors when something fails. B) If you echo mysqli_error($dbc) as part of your error reporting logic, it will tell you why the prepare statement failed. Quote Link to comment https://forums.phpfreaks.com/topic/248311-warning-mysqli_stmt_bind_param-expects-parameter-1/#findComment-1275096 Share on other sites More sharing options...
doubledee Posted October 3, 2011 Author Share Posted October 3, 2011 Come on guys, you should have helped me catch this one... Apparently it wasn't such a great idea to have a table named SHOW (or possibly a field name date)... Debbie Quote Link to comment https://forums.phpfreaks.com/topic/248311-warning-mysqli_stmt_bind_param-expects-parameter-1/#findComment-1275097 Share on other sites More sharing options...
doubledee Posted October 3, 2011 Author Share Posted October 3, 2011 Your prepare is failing due to an error of some kind. A) You always need to use error checking/error reporting logic in your code so that you don't trigger follow-on errors when something fails. B) If you echo mysqli_error($dbc) as part of your error reporting logic, it will tell you why the prepare statement failed. You mean code that exits "gracefully" versus throwing an error like I got in NetBeans? If so, how would you modify my code? Debbie Quote Link to comment https://forums.phpfreaks.com/topic/248311-warning-mysqli_stmt_bind_param-expects-parameter-1/#findComment-1275099 Share on other sites More sharing options...
Buddski Posted October 3, 2011 Share Posted October 3, 2011 Ignore my last statement(s), I totally misread your code and was giving information based on the mysqli_stmt_prepare function. As for the problem at hand, you can wrap your column\table names in back-ticks $q = 'SELECT `id`, `name`, `location`, `date` FROM `show` WHERE `id`=?'; Quote Link to comment https://forums.phpfreaks.com/topic/248311-warning-mysqli_stmt_bind_param-expects-parameter-1/#findComment-1275100 Share on other sites More sharing options...
doubledee Posted October 3, 2011 Author Share Posted October 3, 2011 Ignore my last statement(s), I totally misread your code and was giving information based on the mysqli_stmt_prepare function. As for the problem at hand, you can wrap your column\table names in back-ticks $q = 'SELECT `id`, `name`, `location`, `date` FROM `show` WHERE `id`=?'; Okay, but is using SHOW for a table or DATE for a field, evil?? Debbie Quote Link to comment https://forums.phpfreaks.com/topic/248311-warning-mysqli_stmt_bind_param-expects-parameter-1/#findComment-1275101 Share on other sites More sharing options...
Buddski Posted October 3, 2011 Share Posted October 3, 2011 I wouldn't say evil, its not good practice but there are ways around it as you can see Quote Link to comment https://forums.phpfreaks.com/topic/248311-warning-mysqli_stmt_bind_param-expects-parameter-1/#findComment-1275106 Share on other sites More sharing options...
darkfreaks Posted October 3, 2011 Share Posted October 3, 2011 to be Frank SHOW is a MYSQL reserved word i would refrain from using it in a table name, as it would conflict with the MYSQL function name. not so sure about date. hers is what i would do. if($stmt = mysqli_prepare($dbc, $q)){ //execute query $stmt->execute(); //bind parameter $stmt->bind_param('i',$id); } Quote Link to comment https://forums.phpfreaks.com/topic/248311-warning-mysqli_stmt_bind_param-expects-parameter-1/#findComment-1275107 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.