error Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in
Code (PHP)
<form action="" method="post" enctype="multipart/form-data">
<table width="500px" style="background-color:#DCDCDC;padding:20px;border-radius: 10px 10px 10px 10px;" align="center">
<tr>
<td align="center" >Import Excel</td>
</tr>
<tr>
<td align="center">
<input type="file" name="FileUpload">
<input type="submit" name="submit" value="Import">
</td>
</tr>
</table>
</form>
<?php
if($_POST['submit'])
{
function MultiUploadimage($FileUpload,$tmps,$oldfiles,$directory)
{
$path = $directory;
$rand = substr(str_shuffle('ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'),0,15);
if(trim($tmps) != "")
{
@unlink($path."/".$oldfiles);
$Files = $FileUpload;
$tmp = $tmps;
$New_Files = $rand.'-'.$FileUpload;
move_uploaded_file($tmp,$path."/".$New_Files);
}
else
{
$Files = $oldfiles;
$New_Files = $Files;
}
return $New_Files;
}
$FileUpload = trim($_FILES["FileUpload"]["name"]);
$tmps = $_FILES["FileUpload"]["tmp_name"];
$oldfiles = '';
$directory = "MyXls";
$new = MultiUploadimage($FileUpload,$tmps,$oldfiles,$directory);
//*** Get Document Path ***//
$strPath = realpath(basename(getenv($_SERVER["SCRIPT_NAME"]))); // C:/AppServ/www/myphp
$OpenFile = "MyXls/".$new;
//*** Create Exce.Application ***//
$xlApp = new COM("Excel.Application");
$xlBook = $xlApp->Workbooks->Open($strPath."/".$OpenFile);
$xlSheet1 = $xlBook->Worksheets(1);
?>
<table width="420" border="1" align="center">
<?php
$i=1;
while($xlSheet1->Cells->Item($i,1) != "")
{
?>
<tr align="center">
<td><?=$xlSheet1->Cells->Item($i,3);?></td>
<td><?=$xlSheet1->Cells->Item($i,9);?></td>
</tr>
<?php
$i = $i + 1;
}
?>
</table>
<br />
<?php
//*** Insert to MySQL Database ***//
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("my4ib_new");
$i=2;
while($xlSheet1->Cells->Item($i,2) != "")
{
$strSQL = "SELECT * FROM insurance_id WHERE car_body = '".$xlSheet1->Cells->Item($i,9)."' ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$objResult = mysql_fetch_array($objQeury);
echo $strSQL;
if(!$objResult)
{
$strSQL = " ";
$strSQL .= "INSERT INTO insurance_id ";
$strSQL .= "(id_insurance,car_body) ";
$strSQL .= "VALUES ";
$strSQL .= "('".iconv( 'TIS-620','UTF-8',$xlSheet1->Cells->Item($i,3))."','".$xlSheet1->Cells->Item($i,9)."') ";
mysql_query("SET NAMES UTF8");
$objQuery = mysql_query($strSQL);
if($objQuery)
{
echo "Save Done.";
}
else
{
echo "Error Save [".$strSQL."]";
}
}
$i = $i + 1;
}
@mysql_close($objConnect);
?>
<?php
//*** Close & Quit ***//
$xlApp->Application->Quit();
$xlApp = null;
$xlBook = null;
$xlSheet1 = null;
}
?>
Error
error Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\MBLT\PHPExcel\Read.php on line 79 อะครับ
Tag : PHP, Excel (Excel.Application)
Date :
2013-08-23 13:29:42
By :
Mpiyaphon
View :
816
Reply :
2
ผมลองใส่ or die (mysql_error()); หมดแล้วครับ แต่ไม่มีอะไรขึ้นเลย มีอยู่บรรทัดเดียวคือ Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\MBLT\PHPExcel\Read.php on line 79 เหมือนเดิมเลยครับ
Date :
2013-08-26 11:22:15
By :
Mpiyaphon
Load balance : Server 04