php - SQL code for checking user log in data -


I want to type a code to login the user's username and password to log in, but only every time Successfully logs in to run it:

  & lt; PHP $ Conn = mysql_connect ('localhost', 'root'); If (! $ Conn) died ("Could not connect". Mysql.error ()); Mysql_select_db ('swimsafe'); If (isset ($ _ post ['chkdbforpass'])); {$ Email = $ _ POST ['chkdbforemail']; $ Pass = $ _ post ['chkdbforpass']; $ Sql ​​= 'Select * From user where email address = "$ email" and password = "$ pass";; $ Result = mysql_query ($ sql, $ conn); If (! $ Result) died ("Could not query". Mysql_error ()); Echo ("successfully logged in!"); Setcookie ('username', $ email); } Mysql_close (); ? & Gt;  

Is it enough or do you have more information?

mysql _ * is excluded please PDO Or use MySQLi .

An OAP to check logins using mysqli (this also takes care of the prevention of SQL injection) The method is:

  & lt ;? Php // connect $ mysqli = new mysqli ("localhost", "my_user", "my_password", "my_database"); If (mysqli_connect_errno ()) {printf ("Connect failed:% s \ n", mysqli_connect_error ()); Go out(); } // Prepare a prepared statement ($ stmt = $ mysqli- & gt; Create ("Choose COUNT (*) as the user name as the user where email address =? And password =?") {/ / Bind Ultimate - SQL Injection Troubleshoot $ '_POST [' chkdbforemail ']:' ', isset ($ _ POST [' chkdbforpass']) $$ _POST ['chkdbforpass']  carry about (); // result result row $ result = $ stmt-> Get_result (); $ Line = $ result- & gt; Fetch_assoc (); // check login if login ("$ sign ['userExists']) & amp; amp; and (int) $ line ['userExists'] & gt; = 1) {// login login" Echo; } Else {// login error "email address and / or password is incorrect."; } // Close statement $ stmt-> Close (); } // Close connection $ mysqli- & gt; Close (); ? & Gt;  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -