mysqli_fetch_array() expects parameter 1 to be mysqli_result, bool given in - PHP on line 12

2
(814 Views)

×

Please Login or Register to process.

I am working with PHP and MYSQL database . I am getting an error mysqli_fetch_array() expects parameter 1 to be mysqli_result, bool given in C:\xampp\htdocs\hp_gas\update.php on line 12 .

I am attaching my PHP code.  

<?php 

$host = 'localhost';

$username = 'root';

$pass = '';

$db = 'tutorial';

$conn = new mysqli($host,$username,$pass,$db);

$id=$_GET['id'];

$result = mysqli_query($conn,"SELECT from added_date Where id=$id");

while($res=mysqli_fetch_array($result)){

$issuedate = $res['i_date'];

}

 ?>

HTML form code -

<!DOCTYPE html>

<html>

<head>

<title></title>

</head>

<body>



<?php 



if (isset($_POST['submit'])) {



$id = $_POST['id'];



$issuedate = $_POST['issuedate'];

$result = mysqli_query($conn, "UPDATE added_date set i_date='$issuedate' WHERE id=$id");

echo "Updated";

} else{

echo "Sorry";

}

?>



<form method="post" action="">

<label>Issue Date</label>

          <input type="date" name="issuedate" id="issuedate"  class="form-control" value="<?php echo $issuedate; ?>">

          <br>



          <input type="hidden" name="id" value=<?php echo $_GET['id']; ?>>

          <input type="submit" name="submit">

</form>

</body> 

</html>

 

I am updating data using PHP and MYSQL database but getting error like mysqli_fetch_array() expects parameter 1 to be mysqli_result, bool is given. 

How can I fix this error in PHP? 

 

asked 25 Aug 2020 in PHP by mishal(180 Points)

Share

3 Answers
answered 25 Aug 2020 by vishalrana1(7.3K Points) (edited)
1

I have checked your code. You are working for update operation in PHP with an MYSQL database. You have many issues in your code. As I can see, you are getting "mysqli_fetch_array() expects parameter 1 to be mysqli_result, bool given in ". This happens when you did a mistake in your connection file or query. Your MySQL query looks good but the connection is not well. 

I am removing issues from your PHP code.  

$host = 'localhost';
$username = 'root';
$pass = ' ';
$db = 'tutorial';
$conn = mysqli_connect($host,$username,$pass,$db);

Kindly check these PHP lines and update your code.

You can learn from the tutorial - Update operation in PHP with  MYSQL database

 


Comment

answered 25 Aug 2020 by shakti(9.1K Points)
2

You are missing PHP mysqli_connect() function and syntax error in connection code. You have used a new keyword with mysqli. First, of understanding the error "mysqli_fetch_array() expects parameter 1 to be mysqli_result, bool is given" This error shows that the variable values are not coming or something missing in your MYSQL query, connection variable. Make sure to update these two lines - 

$pass = ' ';

and the next line. 

$conn = mysqli_connect($host,$username,$pass,$db);

No need to use the NEW keyword. 

Kindly check all syntaxes, functions, and query before the mysqli_fetch_array() function. 


Comment

answered 25 Aug 2020 by vishalrana1(7.3K Points) (edited)
1

As you can see, I have answered the above. One more line has an issue in your PHP code. 

You are missing the asterisk * symbol in your PHP query. 

$result = mysqli_query($conn,"SELECT* FROM added_date WHERE id=$id");

 


Comment

Related Questions :-

Your Answer

You can post your answer after login..