What is returned by SQL when no record is found?

Source: Internet
Author: User
I have a login interface. If the user name does not exist when entering the user name, a registration prompt is prompted, but it is clear that I may not know the SQL statement, so there is always a problem, even if you enter a user name that does not exist in the database during debugging, no prompt is displayed. if (! Empty ($ _ POST [& #039; login & #039;]) {... I have a login interface. If the user name does not exist when entering the user name, a registration prompt is prompted, but it is clear that I may not know the SQL statement, so there is always a problem, even if you enter a user name that does not exist in the database during debugging, no prompt is displayed.
If (! Empty ($ _ POST ['login']) {

// If the user name does not exist, the system prompts $ isset_ SQL = "select username from user where username = '$ username'"; $ is_exist = mysql_query ($ isset_ SQL); if (! $ Is_exist) {echo "script" alert ('the current user does not exist. Please check or select to register! '); Window. location. href = 'Article. login. php' script "; exit ();}
$query = "select password from user where username='$username'";..............

Reply content:

I have a login interface. If the user name does not exist when entering the user name, a registration prompt is prompted, but it is clear that I may not know the SQL statement, so there is always a problem, even if you enter a user name that does not exist in the database during debugging, no prompt is displayed.
If (! Empty ($ _ POST ['login']) {

// If the user name does not exist, the system prompts $ isset_ SQL = "select username from user where username = '$ username'"; $ is_exist = mysql_query ($ isset_ SQL); if (! $ Is_exist) {echo "script" alert ('the current user does not exist. Please check or select to register! '); Window. location. href = 'Article. login. php' script "; exit ();}
$query = "select password from user where username='$username'";..............

First, do not usemysql_*A series of connection methods. ChangePDOOrMySQLi

Then your answer:mysql_queryYou only need to executemysql_fetch_assocTo obtain the database response.

Warning:mysql_*It has been officially removed by PHP.

// Connect to the Database Section $ db = new PDO ('mysql: host = localhost; dbname = database name', 'username', 'Password '); $ db-> exec ('set names utf8 '); // use preprocessing to solve the SQL injection vulnerability $ stmt = $ db-> prepare ('select username from user where username =: username '); // bind the parameter $ stmt-> bind (': username', $ username, PDO: PARAM_STR); // execute the query $ stmt-> execute (); // get data $ user = $ stmt-> fetchColumn (); echo $ user? 'Registered ': 'unregistered ';

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.