-3
<!doctype html>
<html>
<head>
<title>All</title>
</head>
<body>
<?php
include ("connection.php");

$result = mysqli_query($con, "SELECT * FROM student_data") or die('Query failed');

while($row = mysqli_fetch_array('$result'))
  {
  echo $row['name'];
  echo $row['fname'];
  echo $row['sid'];
  echo $row['email'];
  echo "<br>";
  }
?>
</body>
</html>

This i suppose to print every data in the database. But i get the following error. Where am i going wrong? enter image description here

user3520573
  • 137
  • 1
  • 6
  • 13
  • 1
    Variables under single quotes **will not be parsed**. `mysqli_fetch_array($result))` – AyB Apr 24 '14 at 06:27
  • 1
    @ICanHasCheezburger — Even if they were, it would still be a string and not a result object. – Quentin Apr 24 '14 at 06:28
  • possible duplicate of [mysqli\_fetch\_array() expects parameter 1 to be mysqli\_result, boolean given in](http://stackoverflow.com/questions/15439919/mysqli-fetch-array-expects-parameter-1-to-be-mysqli-result-boolean-given-in) – Hüseyin BABAL Apr 24 '14 at 07:12

4 Answers4

3

remove apostrophe around $result. This mysqli_fetch_array('$result') should be mysqli_fetch_array($result)

Note the difference:

'$result' is a string (single apostrophe)

$result is a resource returned by mysqli_query

Fracsi
  • 2,274
  • 15
  • 24
1

The error message complains that you are passing it a string instead of a result.

You have quotes around '$result'. That makes it a string. Don't do that.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
0

Replcae the following line

while($row = mysqli_fetch_array('$result'))

with this one while($row = mysqli_fetch_array($result))

Keyur Mistry
  • 926
  • 6
  • 18
0

when '$result' or "$result" is used php will read it as a text string. In your issue it needs to be a php variable.