Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- DEFINE ('DB_USER', 'root'); //mysql username
- DEFINE ('DB_PSWD', 'test'); //mysql password
- DEFINE ('DB_HOST', 'localhost'); //mysql host
- DEFINE ('DB_NAME', 'accounts'); //mysql databse
- $dbcon = mysqli_connect(DB_HOST,DB_USER,DB_PSWD,DB_NAME); //connect to db
- if (mysqli_connect_errno()) { //check if can connect to db
- echo "Failed to connect to MySQL: " . mysqli_connect_error(); //if cant display the error msg
- }
- $myUsername = $_POST['user']; //get the typed user details
- $myPassword = $_POST['pass']; //get the typed password details
- $myUsername = stripslashes($myUsername); //this is against sql injection
- $myPassword = stripslashes($myPassword); //this is against sql injection
- $query = "SELECT * FROM users WHERE username='$myUsername'
- and password='$myPassword'"; //check if the user and password are correct
- $result = mysqli_query($dbcon,$query); //add the query to results
- $count = mysqli_num_rows($result); //check row number count
- if($count==1){ //if correct
- echo 'you are now logged in'; //then log in
- }else{
- echo 'did not work'; //else dont log in
- }
- mysqli_close($dbcon); //close database connection
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement