Jump to content

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in PHP?


crf1121359

Recommended Posts

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?

 

 

 

<?php
error_reporting
(E_ALL);
ini_set('display_errors', '1');
?>
<?php
ob_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, password
FROM members
WHERE 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 connection
if (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
Share on other sites

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
Share on other sites

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
Share on other sites

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);
}
Edited by crf1121359
Link to comment
Share on other sites

 

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
Share on other sites

 

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.