Question:
php error mysql_num_rows not a valid mysql
gopi n
2008-08-07 04:02:08 UTC
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/webuser/html/gopinathan/uploadme.php on line 21

if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0) {
$fileName = $_FILES['userfile']['name']; //The original name of the file on the client machine.
$tmpName = $_FILES['userfile']['tmp_name']; //The temporary filename of the file in which the uploaded file was stored on the server.
$fileSize = $_FILES['userfile']['size']; //The size, in bytes, of the uploaded file.
$fileType = $_FILES['userfile']['type'];//The mime type of the file, if the browser provided this information. An example would be "image/gif".

$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content); //Quote string with slashes
fclose($fp);

if(!get_magic_quotes_gpc()) { //Gets the current configuration setting of magic quotes gpc
$fileName = addslashes($fileName);
}
//include("{$_SERVER['DOCUMENT_ROOT']}/phpmyadmin/dbconnect.php");
$find_duplication="SELECT name from tbl_upload where name='".$fileName."'";
$res_duplication=mysql_num_rows($find_duplication);
/* if($res_duplication) {
die(mysql_error());
}*/
if($res_duplication == 0) {

$query = "INSERT INTO tbl_upload (name, size, type, content ) VALUES ('$fileName', '$fileSize', '$fileType', '$content')";

mysql_query($query) or die('Error, query failed');
echo "Record added Successfullly";
}
else {
echo "Sorry record already exist";
}

echo "
File $fileName uploaded
";
}
mysql_close();
Four answers:
village
2008-08-07 04:19:22 UTC
You should follow the pattern:



$link = mysql_connect("localhost", "mysql_user", "mysql_password");

mysql_select_db("database", $link);



$query = "SELECT * FROM table1";

$result = mysql_query($query,$link);

$num_rows = mysql_num_rows($result);



Note:

Pass recordSet in mysql_num_rows instead of query.



Free PHP Resource

http://www.rapidsharehub.com/tag-php-books-PageZ1
hodnett
2016-10-21 07:46:25 UTC
you receives this mistake in case your mysql_query returns fake, this may be because the tables or fields interior the question do not exist, or the syntax of the question is inaccurate (which it isn't), so examine that. you may also note the following blunders on your code: $password = md5(md5("hdihdlfih".$password."Hd6hD5fi3... including "hdihdlfih" and "Hd6hD5fi3" to the starting up and end of a password does no longer replace something, you want to characteristic a special fee for each person (oftentimes commonly used as a salt), as an instance: $password = md5($password.$userid); the position $userid is a special id for each person pulled from the database, you may also comprehend that md5() is an really weak set of regulations and doing it two times wont replace something, you may seem into utilising something like crypt(). $question = mysql_query("go with * FROM consumers the position username='$person'"); variables are case-comfortable and putting $person rather of $person wont paintings. different stuff that you would care about: if ($person) and if ($password) even tho it shouldnt be a challenge, if a username or a password of a person equivalates to fake (which includes "0") then this may fail, you would possibly want to apply if(isset($person)); rather. require("connect.own homestead web page"); if for some reason requiring the report fails then your script will throw a perilous blunders and give up executing , you're a lot extra effective utilising include_once("./connect.own homestead web page"); and then checking the relationship if($connection) and utilising your own blunders message if the relationship failed.
music_ed_29
2008-08-07 04:19:57 UTC
The magic line "resource in /home/webuser/html/gopinathan/uploadme.p... on line 21"

Is broken.

Did you copy and past the code from internet?

Try

$res_duplication= mysql_num_rows ($find_duplication);

I guess that's what is meant
Tizio 008
2008-08-07 04:16:13 UTC
the line is trucated...

$find_duplication="SELECT name from tbl_upload where name='".$fileName."'";

$res_duplication=mysql_num_rows($fi...



anyway... it seems like you have not "submitted" the query to the db! you must do it, before calling mysql_num_rows!


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...