I am new to php, I am converting an ASP website to PHP.
I have a file with sql statements inside it.
Here's what I need to do:
1. check if the file has been uploaded before.
2. if not, then insert the new file name into the DB and then read the file line for line and execute the sql statements. then delete the file
3. if it has been uploaded before, then redirect stating that the file has already been uploaded
here is my code sofar
Code: Select all
<?
//----check if the file exists in the database
$link = mysql_connect("localhost");
mysql_select_db("web_cpd", $link);
$strSql = "SELECT * FROM tblFiles WHERE file_name = '" . $file_name . "'";
if (!$result = mysql_query($strSql, $link)) {
mysql_close($link);
$link = mysql_connect("localhost");
mysql_select_db("web_cpd", $link);
//--- insert the file name into the db
$strSql = "INSERT INTO tblFiles (File_Name) VALUES ('" . $file_name . "')";
mysql_query($strSql, $link);
//---------------------------//
//Insert file values into Database
$my_file = "./new_files/" . $file_name;
$f = fopen($my_file,"r");
while ($r=fread($f,8192) ) {
mysql_close($link);
$link = mysql_connect("localhost");
mysql_select_db("web_cpd", $link);
mysql_query($r, $link);
}
fclose($f);
unlink($f);
//---------------------------//
}
else {
die ("File Already uploaded!");
}
mysql_close($link);
?>when i copy the sql statement that select's the filename from the db into the control centre and execute it I get the following error:
[NOFRIENDS] ERROR 1146: Table 'web_cpd.impossible where noticed after reading const tables' doesn't exist
I am using MySQL as a Database server.
Any help would be greatly appreciated.
Regards