|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
PHP Help
Hi,
i know this is a asp forum, but I need help with writing this php page, and I am stuck! 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:
<?
//----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);
?>
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 |
|
#2
|
|||
|
|||
|
i'm rather new to php myself, but i noticed you had
if (!$result = mysql_query($strSql, $link)) { why not just if ($result == mysql_query($strSql, $link)) { |
|
#3
|
||||
|
||||
|
I would recommend taking a look, and maybe signing up, at the
parent forum to forums.aspfree.com: http://forums.devshed.com/index.php?? There are some very smart people in that community who can answer most any php problem you throw at them.
__________________
__________ Matty. |
|
#4
|
||||
|
||||
|
Thanx Mathew,
looks like I will find my answer there. Keep up the good work ![]() regards noFriends |
|
#5
|
||||
|
||||
|
file upload can get a little tricky. You can also check out php.net for the official php documentation
![]() |
|
#6
|
||||
|
||||
|
official documentations tend to get really confusing and lack any real sample codes... I've learned to learn from other sources, if possible - forums are the best resource.
![]() |
|
#7
|
|||
|
|||
|
Quote:
You know, recommending that people don't visit documentation is kind of counter-productive ![]()
__________________
====== Doug G ====== I didn't attend the funeral, but I sent a nice letter saying I approved of it. --Mark Twain |
|
#8
|
||||
|
||||
|
I'm not saying this - I'm saying they should first search for more direct answers, with sample code and more plain english. if such info can't be found, of course documentation is the next step. also, documentation tends to be huge... one can simply drown in it and never find whatever he/she really needs - that's when guiding hand makes all the difference.
![]() |
|
#9
|
||||
|
||||
|
Thanx for all the input guys,
I got it working after a while, posted a thread at a php forum, with no luck, not the same standard of users as ASPFree ![]() Used simple trial and error and got it working. Thanx again. |
|
#10
|
||||
|
||||
|
glad to see you're better... sometimes trial and error is the best solution.
![]() |
|
#11
|
||||
|
||||
|
Thanx Shadow, much better 2day, atleast have the strength to spend some time here
![]() |
|
#12
|
||||
|