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.
you parameter order to mysql_query
is incorrect. First the query then the connection.
mysql_query("SELECT * FROM priority", $connect);
you have given wrong connection. Should looks like this
$result = mysql_query("SELECT * FROM priority",$connect );
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
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);
$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
$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