Php+mysql Implement login to verify login and password is correct, MySQL login _php tutorial

Source: Internet
Author: User
Tags learn php learn php programming mysql login

Php+mysql to verify that the login and password are correct when logging on, MySQL logon name


Straight into the topic, first look at the PHP check the login name and password is the correct code:

<?php $servername = "server name"; $username = "account name"; $password = "password"; $dbname = "database name";? ><?php//session needs to be started first. Session_Start (); Determine if uname and PWD are assigned if (Isset ($_post[' uname ')) && isset ($_post[' pwd ')) {$name = $_post[' uname ']; $pwd = $_post[' PWD ']; Connect database $conn = new mysqli ($servername, $username, $password, $dbname); if ($conn->connect_error) {die ("Connection failed:". $conn->connect_error); }//Verify that the content matches the database's records. $sql = "SELECT * from Test_students_all WHERE (student_name= ' $name ') and (password= ' $pwd ')"; Executes the above SQL statement and assigns the result set to results. $result = $conn->query ($sql);  Determine if the number of records in the result set is greater than 0 if ($result->num_rows > 0) {$_session[' user_account ') = $name; Output per row data while ($row = $result->fetch_assoc ()) {echo '

' . $row [' STUDENT_NBR ']. '
' . $row [' Student_name ']. ' ('. $row [' sex ']. ')' . '
' . $row [' class ']. '
' . $row [' Major ']. '

'; //

Echo '

'; }} else {echo "does not have the information you want";} $conn->close (); }?> <title>Login Check</title>

<?php//Isset (XX) test if XX set the IF (Isset ($_session[' User_account ')) {echo ' Hello, '. $_session[' User_account ']; } else{echo ' visitors '; }//$conn->close ();?>

The above is the whole content of this article, I hope that you learn PHP programming help.

http://www.bkjia.com/PHPjc/1125887.html www.bkjia.com true http://www.bkjia.com/PHPjc/1125887.html techarticle Php+mysql Implement login to verify the login name and password is correct, MySQL login straight into the topic, first check the PHP check the login name and password is correct code: PHP $servername = "Server name ...

  • 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.