Using php to read from mySQL database. Please help.?

tiger

New member
Here is the code

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("my_db", $con);

$query = "SELECT Username, Password FROM Officer";
$result = mysql_query($query);

while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo "Name :{$row['Username']} <br>" .
"Subject : {$row['Password']} <br>" ;
}

mysql_close($con);
?>

when i run it on my server i get this error


Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in I:\XAMPP\xampp\htdocs\test_php_mySQL3.php on line 13

what am i doing wrong here?
 
Back
Top