0

Possible Duplicate:
mysql_fetch_array() expects parameter 1 to be resource, boolean given in select

I am receiving the following two errors:

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\SystemVehicle\delete_multiple.php on line 51

Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in C:\xampp\htdocs\SystemVehicle\delete_multiple.php on line 75

$sql="SELECT * FROM $userlogin";
$result=mysql_query($sql);

//count table row
$count=mysql_num_rows($result);
?>
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td><form name="form1" method="post" action="">
<table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td bgcolor="#FF0000">&nbsp;</td>

<td colspan="4" bgcolor="#FF0000"><strong>Delete multiple rows in mysql</strong> </td>
</tr>
<tr>
<td align="center" bgcolor="#FF0000">#</td>
<td align="center" bgcolor="#FF0000"><strong>name</strong></td>
<td align="center" bgcolor="#FF0000"><strong>matric</strong></td>
<td align="center" bgcolor="#FF0000"><strong>Position</strong></td>
<td align="center" bgcolor="#FF0000"><strong>Department</strong></td>
<td align="center" bgcolor="#FF0000"><strong>UserName</strong></td>
<td align="center" bgcolor="#FF0000"><strong>Password</strong></td>
<td align="center" bgcolor="#FF0000"><strong>Email</strong></td>
</tr>

<?php
while($result=mysql_fetch_array($row)){
?>

How can these be resolved?

Community
  • 1
  • 1
Nur Hidayah
  • 1
  • 1
  • 1
  • 2
    Generally you'll see this if there was an error in a previous step. Check the return value of `mysql_error()`. – Michael Mior Dec 30 '12 at 04:12
  • 2
    Please don't use `mysql_*` functions, it's deprecated (see [*red box*](http://php.net/manual/en/function.mysql-query.php)) and vulnerable to sql-injection. Use [*PDO*](http://php.net/manual/en/book.pdo.php) or [*MySQLi*](http://php.net/manual/en/book.mysqli.php). That said, switching between `$result` and `$row` in your last line of code - will fix your bug: `mysql_fetch_array()` expects a resource as an input and its output is a row, not vice verse! – Nir Alfasi Dec 30 '12 at 04:20
  • 1
    First please stop using mysql_* functions. Second, please stop being lazy and use the error reporting functions in the mysql driver. In this case mysql_error. Third, please validate the variables that they contain what you need before using them. – Xnoise Dec 30 '12 at 15:42

3 Answers3

0

$row does not exist (ie, it is not a resource)

Did you mean $result?

EDIT: Just saw the update, have you tried echoing the mysql_error()?

David Harris
  • 2,697
  • 15
  • 27
0

You should fetch query arrays..

    <?php
    while($row=mysql_fetch_array($result))
    {
echo $row['some_column'];
     }
    ?>
Xfile
  • 674
  • 8
  • 19
  • actually I copied from this http://www.phpeasystep.com/mysql/10.html can u help me how to fix it? – Nur Hidayah Dec 30 '12 at 05:53
  • OK its $rows not $row.. what do you mean "to fix it"? Its not working? Anyway you should accept answer when you find a right solution by clicking on "correct" mark behind correct answer cauz of you and others too :P ;) – Xfile Jan 01 '13 at 02:16
0

I think you need to see what $userlogin contains and run that query against the database.

In other words, table name: $userlogin doesn't exist or needs to be surrounded with backticks : `$userlogin`

keyboardSmasher
  • 2,661
  • 18
  • 20