PHP Error resource ID #4 when writing login interface
PHP Code
0) {$row =mysql_fetch_assoc ($result); $_session["UserName"]= $UserName; $_session["IsLogin"]=1; Header ("Location:index.php"); } else{Echo ' User name or password error '; }?>
Use the above code processing login always error, ask the big God pointing!! Hurry!!
------Solution--------------------
There is no error. mysql_query () returns a query result set resource identifier (which can be thought of as a pointer to a memory).
The problem with your code is that it is wrong to determine whether the result set is empty, because if the query returns data, the pointer moves (each call returns the record that the current pointer points to, and then the pointer points to the next record), if the Mysql_fetch_array () method is called.
The method to determine whether an empty set is to use Mysql_num_rows ():
PHP code
//if (mysql_fetch_array ($result) >0) {if (mysql_ Num_rows ($result) > 0) {...
------Solution--------------------
mysql_query () succeeds when the resource type variable is returned, and the query fails to return a Boolean type of false. echo is used to output a string, and the variable you want to output needs to be cast to a string, so you get the Resource ID #4
mysql_fetch_array ($result) returns an array or Boolean value of false, It cannot be directly compared to a number, and it is necessary to force the type to be converted to a numeric value. And you later used a similar function of the MYSQL_FETCH_ASSOC (), the error is all about
If it is taught in which tutorial, then you'd better give up this tutorial as soon as possible. If you're writing it yourself, take a look at the basics of the Official Handbook, about the type section, and the description of the MySQL series functions
http://www.php.net/manual/zh/language.types.intro.php
http://www.php.net/manual/zh/book.mysql.php