crf1121359 Posted April 9, 2014 Share Posted April 9, 2014 Hello, this error is driving me crazy! I hope someone could help me out here: This the code for alogin form that I am trying to use but I keep getting this error: Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in PHP? <?phperror_reporting(E_ALL);ini_set('display_errors', '1');?><?phpob_start();session_start();if (isset($_SESSION["username"])) {header("location: index.php"); exit();}?><?php // Parse the log in form if the user has filled it out and pressed "Log In"if (isset($_POST["username"]) && isset($_POST["password"])) {$username = $_POST["username"]; // filter everything but numbers and letters$password = (!empty($_POST['password'])) ? sha1($_POST['password']) : ''; // filter everything but numbers and letters// Connect to the MySQL database include "connect.php";$stmt = mysqli_prepare($db_conx,'SELECT username, passwordFROM membersWHERE username = ?AND password = ?');mysqli_bind_param($stmt, 'ss', $username, $password);$result = mysqli_stmt_execute($stmt);if ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){$_SESSION['id'] = $row['id'];$_SESSION['username'] = $row['username'];$_SESSION['password'] = $row['password'];//and so on//AND CLEAN UP!!mysqli_free_result($result);header("location: index.php");mysqli_stmt_close($stmt);}else {echo 'That information is incorrect, try again <a href="login.php">Click Here</a>';exit();}}?> and this is my config.php file: <?php$db_conx = mysqli_connect("localhost", "XXXX", "TXXXX", "XXXXX");// Evaluate the connectionif (mysqli_connect_errno()) {echo mysqli_connect_error();exit();} else {echo "whoooooooo hoooooooooooooo";}?> could some please help me out with this as it really is bugging me to death. Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/287642-warning-mysqli_fetch_array-expects-parameter-1-to-be-mysqli_result-boolean-given-in-php/ Share on other sites More sharing options...
Psycho Posted April 9, 2014 Share Posted April 9, 2014 Your query is failing or the function mysqli_stmt_execute() is not returning the result of the query $result = mysqli_stmt_execute($stmt); mysqli_stmt_execute() is not a valid PHP function according to the manual. Is that a custom function you created or using from a 3rd party class? Link to comment https://forums.phpfreaks.com/topic/287642-warning-mysqli_fetch_array-expects-parameter-1-to-be-mysqli_result-boolean-given-in-php/#findComment-1475533 Share on other sites More sharing options...
crf1121359 Posted April 9, 2014 Author Share Posted April 9, 2014 On 4/9/2014 at 6:17 PM, Psycho said: Your query is failing or the function mysqli_stmt_execute() is not returning the result of the query $result = mysqli_stmt_execute($stmt); mysqli_stmt_execute() is not a valid PHP function according to the manual. Is that a custom function you created or using from a 3rd party class? No, its not a custom function. I do not have a third party class in my php page either! so what do you suggest ? Link to comment https://forums.phpfreaks.com/topic/287642-warning-mysqli_fetch_array-expects-parameter-1-to-be-mysqli_result-boolean-given-in-php/#findComment-1475535 Share on other sites More sharing options...
crf1121359 Posted April 9, 2014 Author Share Posted April 9, 2014 P.S. i am using mysqli_stmt_execute($stmt); in my registeration form without any problem or error! Link to comment https://forums.phpfreaks.com/topic/287642-warning-mysqli_fetch_array-expects-parameter-1-to-be-mysqli_result-boolean-given-in-php/#findComment-1475536 Share on other sites More sharing options...
Jacques1 Posted April 9, 2014 Share Posted April 9, 2014 Prepared statements don't work like this in MySQLi. Check the manual on how to do them: http://www.php.net/manual/en/mysqli-stmt.bind-result.php Link to comment https://forums.phpfreaks.com/topic/287642-warning-mysqli_fetch_array-expects-parameter-1-to-be-mysqli_result-boolean-given-in-php/#findComment-1475537 Share on other sites More sharing options...
Ch0cu3r Posted April 9, 2014 Share Posted April 9, 2014 You need to call mysqli_stmt_get_result (look at precedural code example for where it is used) after mysqli_stmt_execute Link to comment https://forums.phpfreaks.com/topic/287642-warning-mysqli_fetch_array-expects-parameter-1-to-be-mysqli_result-boolean-given-in-php/#findComment-1475538 Share on other sites More sharing options...
crf1121359 Posted April 9, 2014 Author Share Posted April 9, 2014 On 4/9/2014 at 6:23 PM, Jacques1 said: Prepared statements don't work like this in MySQLi. Check the manual on how to do them: http://www.php.net/manual/en/mysqli-stmt.bind-result.php I am using the prepared statement exactly the same way in my registeration form and it works just fine! look at below code: $stmt = mysqli_prepare( $db_conx, "INSERT INTO tabelname (firstname, lastname) VALUES (?, ?)" ); //after validation, of course mysqli_stmt_bind_param($stmt, "ss", $firstname, $lastname); mysqli_stmt_execute($stmt); if (mysqli_affected_rows($db_conx)) { mysqli_stmt_close($stmt);//<-- CLEAN UP AFTER YOURSELF! //update was successful $id = mysqli_insert_id($db_conx); } Link to comment https://forums.phpfreaks.com/topic/287642-warning-mysqli_fetch_array-expects-parameter-1-to-be-mysqli_result-boolean-given-in-php/#findComment-1475540 Share on other sites More sharing options...
crf1121359 Posted April 9, 2014 Author Share Posted April 9, 2014 On 4/9/2014 at 6:27 PM, Ch0cu3r said: You need to call mysqli_stmt_get_result (look at precedural code example for where it is used) after mysqli_stmt_execute I did that and it brings up this error: Fatal error: Call to undefined function mysqli_stmt_get_result() Link to comment https://forums.phpfreaks.com/topic/287642-warning-mysqli_fetch_array-expects-parameter-1-to-be-mysqli_result-boolean-given-in-php/#findComment-1475541 Share on other sites More sharing options...
Jacques1 Posted April 9, 2014 Share Posted April 9, 2014 On 4/9/2014 at 6:34 PM, crf1121359 said: I am using the prepared statement exactly the same way in my registeration form and it works just fine! look at below code: This is an INSERT statement, not a SELECT statement. Your problem is fetching the rows, which obviously isn't necessary when doing an INSERT query. Link to comment https://forums.phpfreaks.com/topic/287642-warning-mysqli_fetch_array-expects-parameter-1-to-be-mysqli_result-boolean-given-in-php/#findComment-1475542 Share on other sites More sharing options...
mac_gyver Posted April 9, 2014 Share Posted April 9, 2014 On 4/9/2014 at 6:38 PM, crf1121359 said: I did that and it brings up this error: Fatal error: Call to undefined function mysqli_stmt_get_result() that's because your php version isn't >= 5.3 or you are not using the mysqlnd driver, both are required for that function to exist and to work. you will need to read the information about using bind result that Jacques1 posted a link to in reply #5 Link to comment https://forums.phpfreaks.com/topic/287642-warning-mysqli_fetch_array-expects-parameter-1-to-be-mysqli_result-boolean-given-in-php/#findComment-1475607 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.