chishake Posted December 19, 2007 Share Posted December 19, 2007 i have another problem again. i am trying to check if an image i want to upload into my database already exist. i have used the $result= SELECT name from images WHERE name = $name, ($name = $_FILES['userfile']['name']) $result = mysql_query($result); $num=mysql_numrows($result); if($num >0) { echo " there is a file in the database with name $name, upload a different file"; exit(); } this piece of code gives me this error Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource it works on other pieces of data but not on my image table. can anyone tell me why and how i can go about to sort this out since i want to make sure i am not uploading a file already in the database Link to comment https://forums.phpfreaks.com/topic/82335-solved-why-is-no-one-helping-me/ Share on other sites More sharing options...
craygo Posted December 19, 2007 Share Posted December 19, 2007 the function is wrong mysql_num_rows not mysql_numrows Ray Link to comment https://forums.phpfreaks.com/topic/82335-solved-why-is-no-one-helping-me/#findComment-418482 Share on other sites More sharing options...
phpSensei Posted December 19, 2007 Share Posted December 19, 2007 People seem to make this mistake alot. To prevent this, do not use notepad, because if you do, you can't tell if its a real function or not. In other programs, functions turn blue, or another color, so becareful. Link to comment https://forums.phpfreaks.com/topic/82335-solved-why-is-no-one-helping-me/#findComment-418486 Share on other sites More sharing options...
chishake Posted December 19, 2007 Author Share Posted December 19, 2007 that isnt the problem. i have tried mysql_num_rows but still getting the same warning Link to comment https://forums.phpfreaks.com/topic/82335-solved-why-is-no-one-helping-me/#findComment-418489 Share on other sites More sharing options...
phpSensei Posted December 19, 2007 Share Posted December 19, 2007 that isnt the problem. i have tried mysql_num_rows but still getting the same warning try this, and tell us the error that the script spits out. $result = mysql_query($result)or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/82335-solved-why-is-no-one-helping-me/#findComment-418492 Share on other sites More sharing options...
~n[EO]n~ Posted December 19, 2007 Share Posted December 19, 2007 Is that all code you've got Put your sql query inside double quote , like this $result= "SELECT name from images WHERE name = $name"; Link to comment https://forums.phpfreaks.com/topic/82335-solved-why-is-no-one-helping-me/#findComment-418494 Share on other sites More sharing options...
trq Posted December 19, 2007 Share Posted December 19, 2007 If that is your actual code, it is well foobar'd. Post your actual code, within [ code ][/ code ] tags (no spaces). Link to comment https://forums.phpfreaks.com/topic/82335-solved-why-is-no-one-helping-me/#findComment-418496 Share on other sites More sharing options...
Goose87 Posted December 19, 2007 Share Posted December 19, 2007 I dont really understand the ($name={FILES.... part as ive never come across it before, but i'd write it just like this.. ($name = $_FILES['userfile']['name']) $result=@mysql_query("SELECT name from images WHERE name = $name"); $num=@mysql_num_rows($result); if($num >0) { echo " there is a file in the database with name $name, upload a different file"; exit(); } or maybe follow the way you did it and do : $result=@mysql_query("SELECT name from images WHERE name = $name, ($name = $_FILES['userfile']['name'])"); $num=@mysql_num_rows($result); if($num >0) { echo " there is a file in the database with name $name, upload a different file"; exit(); } Hope that works? Link to comment https://forums.phpfreaks.com/topic/82335-solved-why-is-no-one-helping-me/#findComment-418497 Share on other sites More sharing options...
craygo Posted December 19, 2007 Share Posted December 19, 2007 you will also get the error if there is an error with your sql statement. Use Sensei's suggestions below to help debug your sql statement. You may want to start using some Quotes <?php $name = $_FILES['userfile']['name']; $sql = "SELECT `name` from `images` WHERE name = '$name'"; $result = mysql_query($sql) or die(mysql_error()); $num=mysql_num_rows($result); if($num >0) { echo " there is a file in the database with name $name, upload a different file"; exit(); } ?> Ray Link to comment https://forums.phpfreaks.com/topic/82335-solved-why-is-no-one-helping-me/#findComment-418501 Share on other sites More sharing options...
zq29 Posted December 19, 2007 Share Posted December 19, 2007 FYI: Probably a good idea to use a more descriptive topic title in future... Link to comment https://forums.phpfreaks.com/topic/82335-solved-why-is-no-one-helping-me/#findComment-418504 Share on other sites More sharing options...
chishake Posted December 19, 2007 Author Share Posted December 19, 2007 the problem get worst after adding the die(mysql_error()) this is what i get Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in 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 'JPG' at line 1 JPG is the type of file i am trying to upload Link to comment https://forums.phpfreaks.com/topic/82335-solved-why-is-no-one-helping-me/#findComment-418509 Share on other sites More sharing options...
craygo Posted December 19, 2007 Share Posted December 19, 2007 if you echo out $name what do you get??? Link to comment https://forums.phpfreaks.com/topic/82335-solved-why-is-no-one-helping-me/#findComment-418512 Share on other sites More sharing options...
chishake Posted December 19, 2007 Author Share Posted December 19, 2007 this code has solved the problem. <?php $name = $_FILES['userfile']['name']; $sql = "SELECT `name` from `images` WHERE name = '$name'"; $result = mysql_query($sql) or die(mysql_error()); $num=mysql_num_rows($result); if($num >0) { echo " there is a file in the database with name $name, upload a different file"; exit(); } ?> thanks you folks Link to comment https://forums.phpfreaks.com/topic/82335-solved-why-is-no-one-helping-me/#findComment-418520 Share on other sites More sharing options...
phpSensei Posted December 19, 2007 Share Posted December 19, 2007 Mark the topic solved. Link to comment https://forums.phpfreaks.com/topic/82335-solved-why-is-no-one-helping-me/#findComment-418521 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.