PHP Compile Login Interface error resource ID #4

Source: Internet
Author: User
Tags php error
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
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.