Hey all -

I did a bit of searching and read up on the "..not a valid MySQL result resource" error.. but I can't seem to fit any of the solutions to my code.

Can I please get some help?

Here is the error:


Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /nfs/c01/h11/mnt/12486/domains/xx/html/login/signup_backend.php on line 32
We didn't like that.

UPDATED error (after doing a mysql error call):

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 ''members'(username,password,email)VALUES('xx','xx' at line 1

update 2 - after i changed my input syntax to be correct.


Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /nfs/c01/h11/mnt/12486/domains/xx/html/login/signup_backend.php on line 39
We didn't like that.

<?php		
$host="x"; // Host name
$username="x_shortusr"; // Mysql username
$password="x"; // Mysql password
$db_name="x_shortlogin"; // Database name
$tbl_name="x"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");


// username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
$email=$_POST['email'];

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);

// encrypt password
$encrypted_mypassword=md5($mypassword);

$sql="INSERT INTO $tbl_name(username,password,email)VALUES('$myusername','$encrypted_mypassword','$email')";
$result=mysql_query($sql);

#
if(!$result) {
#
echo mysql_error();
#
}

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword");
header("location:woot.php");
}
else {
echo "We didn't like that.";
}
?>

Thanks a ton.. I'm just not quite sure what to do.

Recommended Answers

All 4 Replies

http://www.php.net/mysql_num_rows
mysql_num_rows()
Retrieves the number of rows from a result set.
This command is only valid for statements like SELECT or SHOW that return an actual result set.
To retrieve the number of rows affected by a INSERT, UPDATE, REPLACE or DELETE query,
use mysql_affected_rows().

just the wrong mysql function

http://www.php.net/mysql_num_rows
mysql_num_rows()
Retrieves the number of rows from a result set.
This command is only valid for statements like SELECT or SHOW that return an actual result set.
To retrieve the number of rows affected by a INSERT, UPDATE, REPLACE or DELETE query,
use mysql_affected_rows().

just the wrong mysql function

thanks for the quick reply, and i just switched it.. but I get the same error...


Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in /nfs/c01/h11/mnt/12486/domains/xx/html/login/signup_backend.php on line 39
We didn't like that.

I am such an idiot.

I copied the wrong parts of a script.

Sorry guys. Case closed.

That was the 'jump out and bite me' error
:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.