I am very new to PHP.
Can some one please verify this code and tell me what is the issue.
<?php
require_once 'excel_reader2.php';
$data = new Spreadsheet_Excel_Reader("NZ_Price_List.xls");
error_reporting(E_ALL ^ E_NOTICE);
//start mysql connection
$con=mysqli_connect("localhost","root","ebooks3","newlocalabc");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
for($i=1;$i < $data->rowcount();$i++)
{
$p = $data->val($i,'A');
$sql = sprintf("select count(*) as cnt from products where `isbn` = '%s'", mysql_real_escape_string($p));
$row_dup = mysql_fetch_assoc(mysql_query($sql,$con));
if ($row_dup['cnt'] == 0) {
//insert
}
else{
//update
}
}
echo "hello done";
mysqli_close($con);
?>
I am trying to compare the values from an Excel spreadsheet to database. If the value is already present then just update or if the value is not there then I have to insret the row.
I am getting the following error message:
mysql_fetch_assoc() expects parameter 1 to be resource, null given
Some please let me asap.