0
$q = intval($_GET['q']);

$con = mysqli_connect('localhost','root','','my_db');
  if (mysqli_connect_errno()) {
  echo "Fail to connect :".mysqli_connect_error();
  }

mysqli_select_db($con,"my_db");
$sql="SELECT * FROM ajax WHERE id = '".$q."'";
$result = mysqli_query($con,$sql);

echo "<table border='1'>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
<th>Hometown</th>
<th>Job</th>
</tr>";

while($row = mysqli_fetch_array($result)) {
  echo "<tr>";
  echo "<td>" . $row('Firstname') . "</td>";
  echo "<td>" . $row('Lastname') . "</td>";
  echo "<td>" . $row('AGE') . "</td>";
  echo "<td>" . $row('Hometown') . "</td>";
  echo "<td>" . $row('Job') . "</td>";
  echo "</tr>";
  echo "</table>";
}
mysqli_close($con);

I keep getting this error :Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\abc\getuser.php on line 22

I apologize in advance if there is already an answer to this simple problem, I am new at coding and I have spent quite some time reading other similar questions but still couldn't solve this problem. Thx in advance.

2

2 Answers 2

2

As specified, the argument $result is boolean, not a mysqli_result. In case of error in your SQL request, the function mysqli_query returns false.

You should see why their is a problem with your request by calling mysqli_error just after your mysqli_query if $result is false.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much, called mysqli_error and it return "Unknown column 'id' in 'where clause'", turns out there's no column 'id', my column is 'pid'. Solved. Thx.
0

you could try

$sql=mysqli_query("SELECT * FROM ajax WHERE id = '".$q."' ");

echo "<table border='1'>
.......

while($row = mysqli_fetch_array($sql)) {

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.