(Help) check whether the user name has failed in the database

Source: Internet
Author: User
(Help) check if the user name fails in the database. first, I want to check whether the user name is in the database! Apmserv is built in a local environment and has a bbs database and a meassage table. The table has three fields: id user pass, and the corresponding values are 1 admin; the types are int (10) varchar (25) varchar (25), and there are three local php files:



Conn. php

$ Conn = @ mysql_connect ("localhost", "root", "") or die ("database link error ");
Mysql_select_db ("bbs", $ conn );
Mysql_query ("set names 'utf-8'"); // use UTF-8 Chinese encoding;
?>


Register. php






Login. php




Include ("conn. php ");
If ($ _ POST ["submit"])
$ Name = $ _ POST ['user'];

$ SQL = "select * from message where user = '". $ name ."'";
$ Result = mysql_query ($ SQL) or die ("incorrect account ");
$ Num = mysql_num_rows ($ result );
If ($ num = 0 ){
Echo "account already exists ";
}

?>



Question: no matter what I input in register. php and submit it to login. php, the account already exists, and the original login. php file shows that the account already exists! I wanted to check whether the user name is in the database, but I felt that the database could not be called !!! What's wrong !!


Reply to discussion (solution)

// Form is a get submission.

The following is received using post, and will never enter if.
If ($ _ POST ["submit"])
$ Name = $ _ POST ['user'];

As stated in #1
Mysql_query ("set names 'utf-8'"); // use UTF-8 Chinese encoding;
= "Changed to 'utf8'
Why do you want to receive a submit?
If ($ _ POST ["submit"])
$ Name = $ _ POST ['user'];

Change to $ name = $ _ GET ['user'];
Add echo $ name;

As stated in #1
Mysql_query ("set names 'utf-8'"); // use UTF-8 Chinese encoding;
= "Changed to 'utf8'
Why do you want to receive a submit?
If ($ _ POST ["submit"])
$ Name = $ _ POST ['user'];

Change to $ name = $ _ GET ['user'];
Add echo $ name;







Thank you!

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.