Php mysql simple user login implementation code

Source: Internet
Author: User
Tags mysql tutorial php mysql php tutorial trim

Here is only a reference tutorial for beginners, telling you how to log on as a user. We hope to help you with the mysql tutorial in the php Tutorial.

$ Userid = trim ($ _ POST ["username"]);
$ Userpass = trim ($ _ POST ["password"]);
$ Admin_pass = substr (md5 ($ userpass),); // database tutorial password

Echo $ userid. "<br>". $ admin_pass. "<br>"; // output the user and password [post acquisition];
$ Mysql = new db_mysql (false );
$ Query = "select * from # @ _ admin where admin_id like '". $ userid. "'limit"; // query whether the password has a user name
Echo $ query. "<br> ";
$ Mysql-> SetQuery ($ query );
$ Mysql-> Execute ();
$ Row = $ mysql-> GetObject ();
Echo "database password:". $ row-> admin_pass. "post get password:". $ admin_pass;
// Exit;
If (! Isset ($ row-> admin_id) // The user name is incorrect.
{
ShowMsg ("username error ","../");
$ Mysql-> Close ();
Return 0;
}
Else if ($ row-> admin_pass! = $ Admin_pass) // incorrect password
{
ShowMsg ("incorrect password ","../");
$ Mysql-> Close ();
Return-1;
}
Else
{
ShowMsg ("logon successful ","../");
$ Mysql-> Close ();
Return 1;
}

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.