This question already has an answer here:
I can't figure out what is the problem with the following error:
*Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:...... on line 34*
this is the php code on top of the page before the HTML part:
<?php
session_start();
include("header.php");
include("dbconnection.php");
if(!(isset($_SESSION['customerid'])))
header('Location:login.php?error=nologin');
$result = mysql_query("select * from customers WHERE customerid='".$_SESSION['customerid']."'");
$loan=mysql_query("select * from loan where customerid='".$_SESSION['customerid']."'");
?>
and this is the php code inside the HTML part where its showing the error (line 34, while($arrvar = mysql_fetch_array($loan))
)
<?php
$i=1;
while($arrvar = mysql_fetch_array($loan))
{
echo " <tr>
<td height='30'>'".$arrvar['loanid']."' </td>
<td>'".$arrvar['loantype']."'</td>
<td>'".$_SESSION['customername']."'</td>
<td>'".$arrvar['loanamt']."'</td>
<td>'".$arrvar['interest']."' %</td>
<td>'".$arrvar['startdate']."'</td>
</tr>";
$i++;
}
?>
Your help would be appreciated.
Thanks in advanced.
</div>
You have a typo there on your first SQL query...
$result = mysql_query("select * from customers WHERE ustomerid
^------------ ( Fishy ? )
Must be customerid
instead of ustomerid
on your query and that is why your query fails.
This (mysql_*
) extension is deprecated as of PHP 5.5.0
, and will be removed in the future. Instead, Prepared Statements of MySQLi
or PDO_MySQL
extension should be used to ward off SQL Injection attacks !
Your MySQL query is failing and returning false instead of a result object. Try changing the following:
$loan=mysql_query("select * from loan where customerid='".$_SESSION['customerid']."'") or die(mysql_error());