This question already has an answer here:
When i use this code. It says:
Database access failed: no database selected"
And it also gives the:
Deprecated: mysql_query(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead
error. The following is the code i have used.
$con = mysqli_connect("localhost", "root", "","radian")
or die ("Couldn't connect to mySQL");
$query = "SELECT Staff_id,Fname,Sname,Gender,username FROM staff ";
$result = mysql_query($query);
if (!$result) die ("Database access failed: " . mysql_error());
$rows = mysql_num_rows($result);
for ($j = 0 ; $j < $rows ; ++$j)
{
$row = mysql_fetch_array($result);
$staff_id = $row['Staff_id'];
$Fname = $row['Fname'];
$Sname = $row['Sname'];
$Gender = $row['Gender'];
$username = $row['username'];
echo '<tr> <td>'.$staff_id.'</td> <td>'.$Fname.'</td> <td>'.$Sname.'</td> <td>'.$Gender.'</td> <td>'.$username.'</td> </tr>';
}
It says the error is from this line:
$result = mysql_query($query);
</div>