When using php + MySQL, verify that the logon name and password are correct.

Source: Internet
Author: User
Tags learn php programming

When using php + MySQL, verify that the logon name and password are correct.

Go to the topic and check the php code to check whether the logon name and password are correct:

<? 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 '<p> '. $ row ['student _ nbr ']. '<br/> '. $ row ['student _ name']. '('. $ row ['sex']. ')'. '<br/> '. $ row ['class']. '<br/> '. $ row ['major']. '</p> '; // <p>  </p> echo '<p>  </p> ';}} else {echo" No information you want ";}$ conn-> close () ;}?> <! DOCTYPE html> 

:

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.