While submitting file i get this error-
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Name,Short Description,Description,Address,Phone,Email,Category) VALUES(,,,,,,)' at line 1)
I Tried everything but still my code not working perfectly. Below is my php code-
<div id="form">
<?php
$connect = mysql_connect("mysql6.000webhost.com","username","password");
mysql_select_db("a7611052_123",$connect); //select the table
//Connect to Database
$deleterecords = "TRUNCATE TABLE tablename";
//empty the table of its current records
mysql_query($deleterecords);
//Upload File
if (isset($_POST['submit'])) {
if (is_uploaded_file($_FILES['filename']['tmp_name'])) {
echo "<h1>" . "File ". $_FILES['filename']['name'] ." uploaded successfully." . "</h1>";
echo "<h2>Displaying contents:</h2>";
readfile($_FILES['filename']['tmp_name']);
}
//Import uploaded file to Database
$handle = fopen($_FILES['filename']['tmp_name'], "r");
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$Bn=$data[0];
$Sd=$data[1];
$D=$data[2];
$A=$data[3];
$P=$data[4];
$E=$data[5];
$C=$data[6];
$import="INSERT INTO BusinessD(Business Name,Short Description,Description,Address,Phone,Email,Category) VALUES($Bn,$Sd,$D,$A,$P,$E,$C)";
mysql_query($import) or die(mysql_error());
}
fclose($handle);
print "Import done";
//view upload form
}else {
print "Upload new csv by browsing to file and clicking on Upload<br />
";
print "<form enctype='multipart/form-data' action='B.php' method='post'>";
print "File name to import:<br />
";
print "<input size='50' type='file' name='filename'><br />
";
print "<input type='submit' name='submit' value='Upload'></form>";
}
?>
</div>