-7

I install Xampp on Windows 7, and try to select data from a database table. For this I create code like this:

<?php
$con=mysqli_connect("localhost","test1","2jan1991","test1");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$result = mysqli_query($con,"SELECT * FROM Persons");

while($row = mysqli_fetch_array($result))
  {
  echo $row['FirstName'] . " " . $row['LastName'];
  echo "<br>";
  }

mysqli_close($con);
?>

But when I try to run code it has error like:

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\t2\1.php on line 11

How to resolve this?

Dharman
  • 30,962
  • 25
  • 85
  • 135
user3184656
  • 5
  • 1
  • 1
  • 1

1 Answers1

5
$result = mysqli_query($con, "SELECT * FROM Persons") or die("Error: " . mysqli_error($con));

Can tell you the reason.

user555
  • 1,564
  • 2
  • 15
  • 29
kta
  • 19,412
  • 7
  • 65
  • 47