This is the error message I received:Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in signup_ck.php on line 40

I am trying to teach myself to use PHP and MySQL together. I have a site that needs a special area that should have a login, so I found a set of scripts, and started playing with the code. Now I get an error message. This is the file listed in the error message.

I know this is not nice code, but the scripts I found were using HTML3 and I tried to clean things up using HTML5 and CSS.

Try adding mysql_real_escape_string to escape any characters that will allow for SQL inject. Also consider casting your $userid to an int, ie $userid = (int)$_POST['userid'] it will then no longer require escaping.

CSU_Bill
—
2011-07-27T12:39:16Z —
#3

First, thanks for the quick response. Posting that message was the last thing I did before shutting down for the night.

I have an error message if I am not connected to the database. I have tested this and it worked, but may need some improvement. As I said, I am a rank beginner with PHP, and this is my first attempt at working with MySQL.

I looked at PHP.net and I thought I was checking the database to see if the userid was already in use. The database table member_tbl is currently empty, so I should expect to get my "Userid already assigned." message.

I did notice the PHP.net did not show an example of this using IF. Am I using the wrong function?

CSU_Bill
—
2011-07-29T02:42:06Z —
#10

Almost forgot.

I entered this into my code:$trimmed = trim($userid);var_dump($trimmed);

The result was: string(1) "0"

Can I now enter something like $trimmed = $userid; to get the trimmed userid ready for the remainder of the code?

StarLion
—
2011-07-29T12:08:49Z —
#11

I need a schema for your table to be able to debug this further.

CSU_Bill
—
2011-07-29T12:27:13Z —
#12

I actually have two tables, login_tbl and member_tbl.login_tbl has:id INT(6) NOT NULL AUTO_INCREMENT user_id VARCHAR(10) NOT NULLip VARCHAR(50) NOT NULLtime DATETIME NOT NULL status CHAR(3) NOT NULL' PRIMARY KEY (id)

(Future Hint: The 'is not a mysql resource' error most normally means "Your query was rejected by the server". If you encounter this in the future, run the query through your database engine and you'll find out why. [In this case, mysql would have barked "Field userid does not exist"])

CSU_Bill
—
2011-07-29T13:10:46Z —
#14

StarLion,

Thank you. I am no longer getting warning messages. Now i am just getting the messages I have inserted into my code.

Can I run each line of code via phpMyAdmin to catch my errors?

StarLion
—
2011-07-29T13:46:24Z —
#15

Any query you can run through PHPmyAdmin. You'll have to supply some fake data if you want it to work correctly (IE: Look at your query. phpMyAdmin is going to have no idea what $userid is supposed to be (and will actually handle it as a string literal), so if you want to test it with user_id 1, you'll have to put into phpMyAdmin SELECT userid FROM member_tbl WHERE userid = '1' )

CSU_Bill
—
2011-07-29T14:50:51Z —
#16

StarLion,

Great! I will put in some entries for a couple of different "members" and see what I can learn.

If I don't get this started tonight, it will be next week before i can do anything with it. I will be visiting my newborn grandson this weekend.

// Set status to NOTOK if userid is less than 5 chaqractersif(!isset($userid) or strlen($userid) <5){$msg=$msg."User id should be 5 or more than 5 char length";$status = "NOTOK";}

if($status<>"OK"){ echo "$msg";}else{ // if all validations are passed$query=mysql_query("insert into member_tbl(user_id,password,email,name_last,name_first) values('$userid','$password','$email','$name_last','$name_first')");echo "Welcome, You have successfully submitted new member information