Resourceid #4

Source: Internet
Author: User
Tags mysql functions php error
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

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.