Resourceid #4 PHPcode & lt ;? Session_start (); require & quot; connect. inc. php & quot; if ($ _ GET [& quot; action & quot;] & quot; login & quot ;) {$ UserName $ _ POST [& php error when writing the logon interface Resource id #4
PHP code
0) {$ row = mysql_fetch_assoc ($ result); $ _ SESSION ["UserName"] = $ UserName; $ _ SESSION ["islogin"] = 1; header ("Location: index. php ");} else {echo 'incorrect user name or password ';}?>
When I use the above code to process logon, an error is always reported. please kindly advise !! Urgent !!
------ Solution --------------------
No error. Mysql_query () returns a resource identifier of the query result set (which can be considered as a memory pointer ).
The problem with your code is that the method to determine whether the result set is null is incorrect, because if the query returns data, after calling the mysql_fetch_array () method, the pointer moves (each call returns the record pointed to by the current pointer, and then the pointer points to the next record ).
To determine whether the set is empty, use mysql_num_rows ():
PHP code
// If (mysql_fetch_array ($ result)> 0) {if (mysql_num_rows ($ result)> 0 ){...
------ Solution --------------------
When mysql_query () is successful, the resource type variable is returned. if the query fails, the Boolean type false is returned. Echo is used to output a string, and the variable to be output must be forcibly converted to a string. Therefore, the Resource id #4 is obtained.
Mysql_fetch_array ($ result) returns an array or boolean value of false, which cannot be directly compared with a number. you must first forcibly convert the type to a value. And you later used mysql_fetch_assoc () with similar functions, with hundreds of errors
If the tutorial is taught, you 'd better give up the tutorial as soon as possible. If you write it on your own, first take a look at the basics in the official manual, the types section, and descriptions of mysql functions.
Http://www.php.net/manual/zh/language.types.intro.php
Http://www.php.net/manual/zh/book.mysql.php