File and $link logic?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
noFriends
Forum Newbie
Posts: 3
Joined: Sat Jan 29, 2005 8:25 am

File and $link logic?

Post by noFriends »

hi all,

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)) &#123;

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) ) &#123;
		mysql_close($link);	
		$link = mysql_connect("localhost");
		mysql_select_db("web_cpd", $link);
		mysql_query($r, $link);
   &#125;
   fclose($f);
   unlink($f);
//---------------------------// 
&#125;
else &#123;
 die ("File Already uploaded!");
&#125;
mysql_close($link);		
?>
the problem is, nothing gets uploaded into the db, not even the file name it does the die ("file already uploaded!") section the whole time, even if there is no such file in the db.

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
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

This thread has been moderated. The replies have been moved with the suggestion to ban that lot of juveniles.

We DO NOT tolerate this kind of behaviour here!

Anyone willing to help noFriends, please post below.
Post Reply