I am trying to import some data from a CSV file (with headers) into a MySQL table. I have debugged this script and it seems to be working up until the "Handle" variable. When I run this code, I get a blank screen and the MySQL table is not updated with the CSV data. I may be missing something here. Any help is appreciated!
Thanks,
AME
Here's the code:
<?PHP
error_reporting(E_ALL & ~E_NOTICE);
if (ini_get('display_errors') === FALSE) {
ini_set('display_errors', 1);
}
$dbhost = 'localhost';
$dbuser = 'myusernam';
$dbpasswd = 'mypassword';
$db = "dbname";
$dbh = mysql_connect($dbhost, $dbuser, $dbpasswd) or die("Unable to connect to SQL server");
$my_db = @mysql_select_db($db, $dbh) or die("Unable to select database");
$file = $_SERVER['DOCUMENT_ROOT']."/home/test.csv";
$handle = fopen($file, "r");
while (($fileop = fgetcsv($handle,1000,",")) !==false)
{
$listid = $fileop[0];
$listclass = $fileop[1];
$type = $fileop[2];
$status = $fileop[3];
$remarks = $fileop[3];
$streetaddress = $fileop[6];
$fulladdress = $fileop[6].",".$fileop[7].",".$fileop[8];
$orgname = $fileop[9];
$licenseid = $fileop[10];
$agentname = $fileop[12]." ".$fileop[12];
$imagecount = $fileop[13];
$sql = mysql_query("INSERT INTO markers (id,Class,Status,AskingPrice,Remarks,StreetAddres,address,OrgName,AgentLicenseID,AgentName,ImageCount) VALUES ('$listid','$listclass','$type','$status','$remarks','$streetaddress','$fulladdress','$orgname','$licenseid','$agentname','$imagecount')");
}
if($sql)
{
echo 'data uploaded successfully';
}
?>