I have a database I am loading with personal information. For the most part it is straightforward coding. However, one of the fields contains numeric and alpha data that might be causing problems... and example is
15248521/xbes
this is an important tracking number. It must be inserted into the database just like it shows. However, when I run the query I get this error...
Insert Data 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
'Smith','123 anystreet','anycity','anystate','11121','15278521
since the error cuts off at the / i am thinking that it is what's causing the problem. Can anyone help? Here is the code I am using to imput data.
case "database":
//upload the csv file into the `upload_file` table
$file = $_SESSION['myfile'];
//check if upload_file table has data in it...
$sql_clear="SELECT * FROM upload_file";
$r_clear = mysql_query($sql_clear, $deduper)or die("<br>Check Upload_file table ERROR: " . mysql_error());
if ($r_clear != 0){
//flush all tables
$sqlupload_file = "TRUNCATE TABLE upload_file";
$rupload_file = mysql_query($sqlupload_file, $deduper)or die("Clear Table Error: " . mysql_error());
$sqlbad = "TRUNCATE TABLE bad";
$rbad = mysql_query($sqlbad, $deduper)or die("Clear Table Error: " . mysql_error());
$sqlgood = "TRUNCATE TABLE good";
$rgood = mysql_query($sqlgood, $deduper)or die("Clear Table Error: " . mysql_error());
}
//open file to write to database
$row = 1;
$fp = fopen($file,"r");
//get csv contents and build multi-value list insergt query
while($data = fgetcsv ($fp, 1000, ",")){
$num = count($data);
$telephone = $data[0];
$fname = $data[1];
$lname = $data[2];
$address = $data[3];
$city = $data[4];
$state = $data[5];
$zip = $data[6];
$leadnum = $data[7];
//insert data into database
$sql2 = "INSERT IGNORE INTO upload_file (`telephone`,`fname`,`lname`,`address`,`city`,`state`,`zip`,`leadnum`) VALUES ('$telephone','$fname','$lname','$address','$city','$state','$zip','$leadnum')";
$r2 = mysql_query($sql2, $deduper)or die("<br>Insert Data Error: " . mysql_error());
$row = count($r2);
}//end while loop
echo "<p align=center>Please select the file you want to check.<br><br>
<table border=0>
<form action=index.php?act=upfile enctype=multipart/form-data method=POST>
<tr>
<td>Filename:</td>
<td>
<input type=file name=ufile>
<input type=hidden name=MAX_FILE_SIZE value=60000>
<input type=submit value=Submit>
</td>
</tr>
</form>
</table>";
if($admin==1){
echo "<br><div style=\"over-flow: auto; width: 600px; height: 400px; background-color: #cccccc;\">";
echo "<strong><font color=red>Current Files Ready to scrub</font></strong><br>";
//check for good leads
$sql_good = "SELECT * FROM good";
$r_good = mysql_query($sql_good, $deduper)or die("<br>Good Leads Error: ".mysql_error());
$row_good = mysql_num_rows($r_good);
//check for bad leads
$sql_bad = "SELECT * FROM bad";
$r_bad = mysql_query($sql_bad, $deduper)or die("<br>Bad Leads Error: ".mysql_error());
$row_bad = mysql_num_rows($r_bad);
//if leads exist then display the clear database button
if ($row_good && $row_bad !== 0){
echo "<a href=index.php?act=clearTables&f=$dir".$file2.">Clear database tables</a>";
}//end if
echo "<br><br><strong>Records Inserted into database. Next scrub files.</strong>";
outputScrub();
if($row_good !==0){
echo "<br>Number of good leads: " . $row_good;
}//endif
echo "</div><br><br>";
echo "<br><div style=\"over-flow: auto; width: 600px; height: 400px; background-color: #cccccc;\">";
echo "<strong><font color=red>Current files you have in your dir</font></strong><br>";
outputAvailable();
echo"</div>";
}
break;