
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | //login.php <html> <head> <meta http-equiv= 'Content-Type' content= 'text/html; charset=ISO-8859-1' > <title>Simple PHP MySQLi Login Form</title> </head> <body> <form method= 'post' action= 'validate_login.php' > <table border= '1' > <tr> <td><label for = 'username' >User Name</label></td> <td><input type= 'text' name= 'username' id= 'username' ></td> </tr> <tr> <td><label for = 'users_pass' >Password</label></td> <td><input name= 'users_pass' type= 'password' id= 'users_pass' ></input></td> </tr> <tr> <td><input type= 'submit' value= 'Submit' /> <td><input type= 'reset' value= 'Reset' /> </tr> </table> </form> </body> </html> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <?php $conn = new mysqli( 'localhost' , 'root' , '' , 'testingdb' ); if ( $conn ->connect_error) { die ( 'Error : (' . $conn ->connect_errno . ') ' . $conn ->connect_error); } $username = $_POST [ 'username' ]; $pass = $_POST [ 'users_pass' ]; $sqlc = "SELECT * FROM users WHERE username = '$username' OR password = '$pass'" ; if ( $rsdc =mysqli_query( $conn , $sqlc )){ $total =mysqli_num_rows( $rsdc ); if ( $total == '1' ) { echo '<h1>You are a validated user.</h1>' ; } else { echo '<h1>Sorry, your credentials are not valid, Please try again.</h1>' ; } } ?> |