Hi all, I'm very new to this forum but I'm hoping there are individuals out there who can help me with my issue.
I'm building a database updater tool for a client. I'm sure it used to work but something has happened and now it gives an error. I'm not sure why.
Basically, if I upload a file that has the following content :
CREATE TABLE dealers (id INT NOT NULL AUTO_INCREMENT,name VARCHAR(50) NULL,address VARCHAR(50) NULL,city VARCHAR(50) NULL,state VARCHAR(50) NULL,tel VARCHAR(50) NULL,fax VARCHAR(50) NULL,PRIMARY KEY (id))
It works. But if I upload a file like this :
CREATE TABLE dealers (id INT NOT NULL AUTO_INCREMENT,name VARCHAR(50) NULL,address VARCHAR(50) NULL,city VARCHAR(50) NULL,state VARCHAR(50) NULL,tel VARCHAR(50) NULL,fax VARCHAR(50) NULL,PRIMARY KEY (id))
INSERT INTO dealers (id, name, address, city, state, tel, fax) VALUES (1, 'Test Company', 'Test Rd.', 'Testville', 'Testopolis', '(123) 123-4567', '(123) 123-4567');
It doesn't. Says there is an error in my SQL syntax. Even though, I can take this same file and insert it into my database via phpMyAdmin just fine, no whining.
Here's my code :
<?php
$filename = $FILES['sqlfile']['name'];
$error = $FILES['sqlfile']['error'];
$tmploc = $_FILES['sqlfile']['tmp_name'];
$destloc = "/home/visuals/public_html/test/temp/$filename";
if ($filename != "") {
echo "Copying file from $tmploc to $destloc <BR><BR>";
move_uploaded_file("$tmploc" , "$destloc") or die("Couldn't Upload Your File : $error");
} else {
die("No File Specified");
}
$handle = fopen($destloc, "rt") or die("Could not open file on remote server");
$sql = fread($handle, filesize($destloc));
fclose($handle);
unlink($destloc);
$db = mysql_connect("localhost", "HIDDEN","HIDDEN");
mysql_select_db("HIDDEN",$db);
$result = mysql_query($sql) or die(mysql_error());
echo "Data Replaced";
?>
Any ideas?
--
Ben