0

I have tried to fetch data from priority table of elective_mgmt database.The source code is given below :

<?php
    $connect = mysql_connect("localhost","root","");
    mysql_select_db("elective_mgmt",$connect);
    $result = mysql_query($con,"SELECT * FROM priority");
        echo "<table border='1'>
`<tr>
<th>Name</th>
<th>Roll</th>
<th>Email</th>
<th>Priorityone</th>
<th>Prioritytwo</th>
<th>Prioritythree</th>
</tr>";
while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['Name'] . "</td>";
  echo "<td>" . $row['Roll'] . "</td>";
  echo "<td>" . $row['Email']. "</td>";
  echo "<td>" . $row['Priorityone']."</td>";
  echo "<td" . $row['Prioritytwo']."</td>";
  echo "<td" . $row['Prioritythree']."</td>"; 
  echo "</tr>";
  }
echo "</table>";

mysql_close($con);
?>

 ?>

When I run it ,it displays like this:

Warning: mysql_query() expects parameter 2 to be resource, string given in C:\xampp\htdocs\Elective_management\admin_view.php on line 5

Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in C:\xampp\htdocs\Elective_management\admin_view.php on line 15
Name    Roll    Email   Priorityone Prioritytwo Prioritythree

Warning: mysql_close() expects parameter 1 to be resource, null given in C:\xampp\htdocs\Elective_management\admin_view.php on line 28
?>

I didn't get any idea. Please help me.

suspectus
  • 16,548
  • 8
  • 49
  • 57
Shiva Bhusal
  • 57
  • 10
  • Possible duplicate [mysql_fetch_array() expects parameter 1 to be resource, boolean given in select](http://stackoverflow.com/questions/2973202/mysql-fetch-array-expects-parameter-1-to-be-resource-boolean-given-in-select?answertab=votes#tab-top). – John Conde Jul 11 '13 at 13:42
  • See [this answer](http://stackoverflow.com/a/11674313/250259) for how to troubleshoot this. – John Conde Jul 11 '13 at 13:42

4 Answers4

0

you parameter order to mysql_query is incorrect. First the query then the connection.

mysql_query("SELECT * FROM priority", $connect);
DevZer0
  • 13,433
  • 7
  • 27
  • 51
0

you have given wrong connection. Should looks like this

 $result = mysql_query("SELECT * FROM priority",$connect );
Ruwantha
  • 2,603
  • 5
  • 30
  • 44
0

you shouldnt need the connection variable since you just connected. You should be able to type

$result = mysql_query("SELECT * FROM priority");

and have it work just fine

PlausibleSarge
  • 2,163
  • 1
  • 12
  • 12
0

1 -

mysql_close($con);

here you dont have a $con variable so its empty that why this error show up

Warning: mysql_close() expects parameter 1 to be resource, null given in C:\xampp\htdocs\Elective_management\admin_view.php on line 28 

Fix by : Changing

mysql_close($con);

To

mysql_close($connect);

2 -

$row = mysql_fetch_array($result)`

here you point it to $result and in $result you have $con = Null so this error show up

Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in C:\xampp\htdocs\Elective_management\admin_view.php on line 15

Fix :

Will be fixed when you fix step three


3 -

$result = mysql_query($con,"SELECT * FROM priority");

here again you have the second parameter as a string and it shouldn't be a string so this error show up

Warning: mysql_query() expects parameter 2 to be resource, string given in C:\xampp\htdocs\Elective_management\admin_view.php on line 5

Fix :

Fix by : Changing

mysql_query($con,"SELECT * FROM priority");

To

mysql_query("SELECT * FROM priority",$connect)

PS: If you are just starting coding in this project
Please Consider on changing your syntax from MySql_* to PDO Syntax

Ali Almoullim
  • 1,028
  • 9
  • 30