Verify the logon name and password in php + MySQL

Source: Internet
Author: User
Tags learn php programming
This document describes how to verify the login name and password entered by the user in the database during logon. This document describes how to verify the logon name and password in php + MySQL, if you are interested, you can refer to the "go-to-live" topic to check the correct php login name and password:

<? Php $ servername = "Server Name"; $ username = "account name"; $ password = "password"; $ dbname = "database name";?> <? Php // Session needs to be started first. Session_start (); // determines whether the uname and pwd values are assigned if (isset ($ _ POST ['uname']) & isset ($ _ POST ['pwd']) {$ name = $ _ POST ['uname']; $ pwd = $ _ POST ['pwd']; // connect to the database $ conn = new mysqli ($ servername, $ username, $ password, $ dbname); if ($ conn-> connect_error) {die ("Connection failed :". $ conn-> connect_error);} // verify whether the content matches the database record. $ SQL = "SELECT * FROM test_students_all WHERE (student_name = '$ name') AND (password =' $ pwd ')"; // execute the preceding SQL statement and assign the result set to the result. $ Result = $ conn-> query ($ SQL); // determines whether the number of records in the result set is greater than 0 if ($ result-> num_rows> 0) {$ _ SESSION ['User _ account'] = $ name; // output each row of data while ($ row = $ result-> fetch_assoc () {echo'

'. $ Row ['student _ nbr'].'
'. $ Row ['student _ name'].' ('. $ row ['sex'].') '.'
'. $ Row ['class'].'
'. $ Row ['major'].'

';//

Echo'

';}} Else {echo "no information you want" ;}$ conn-> close () ;}?> Logon verification

<? Php // isset (xx) test whether xx sets if (isset ($ _ SESSION ['User _ account']) {echo 'hello ,'. $ _ SESSION ['User _ account'];} else {echo 'tourists';} // $ conn-> close ();?>

:

The above is all the content of this article. I hope it will help you learn php programming.

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.