Welcome to Techno Smarter QA, Questions, Answers Community
+1 vote
39 views

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? 

in PHP by (160 points) 3

3 Answers

+1 vote

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

by (7k points) 8 27 62
+1 vote

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

$pass = ' ';

and the next  line . 

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

No need to use NEW keyword . 

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

by (8.9k points) 10 22 61
+1 vote

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

You are missing asterisk * symbol in your PHP query. 

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

by (7k points) 8 27 62
...