0

The error I keep getting is: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\PD\admin\view_presidents.php on line 19

I have copied my entire query here. Can anyone help? I can't figure out why I am getting this email.

Thanks,

$bioId = $_GET['bioid'];
require_once('includes/mysql_connect.php');
$sql = 'SELECT * FROM presidents WHERE id='.$bioId;
$result= mysql_query($sql);
$row = mysql_fetch_array($result);
// Retrieve and print every record:

echo '<div class="name">';
echo $row['prez_name'];
echo '</div>';
echo '<div class="rank">';
echo $row['prez_rank'];
echo '</div>';
echo '<div class="served">';
echo $row['prez_served'];
echo '</div>';
echo '<hr />';
echo '<div class="content">';
echo $row['prez_content'];
echo '</div>';
  • Possible duplicate [mysql_fetch_array() expects parameter 1 to be resource, boolean given in select](http://stackoverflow.com/a/11674313/250259) – John Conde May 22 '13 at 01:05
  • Your code is vulnerable at sql injection and deprecated – Sam May 22 '13 at 01:07
  • 1
    Please, **DO NOT** use `mysql_query` in new applications, and **NEVER** use it like this. You're not [escaping your data correctly](http://bobby-tables.com/php) and are leaving yourself wide open to [SQL injection bugs](http://bobby-tables.com/). – tadman May 22 '13 at 01:20

2 Answers2

0

you are not making a check needed :

$bioId = $_GET['bioid'];
require_once('includes/mysql_connect.php');
$sql = 'SELECT * FROM presidents WHERE id='.$bioId;
$result= mysql_query($sql);
if (!$result) { // add this check.
     die('Invalid query: ' . mysql_error());
}
hopper
  • 4,125
  • 8
  • 35
  • 49
0

You simply aren't calling mysql_result: $result=mysql_result(mysql_query($sql));

James
  • 229
  • 1
  • 6
  • 17