Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ob_start();
- $host="localhost"; // Host name
- $username="xxxxx"; // Mysql username
- $password="xxxx="; // Mysql password
- $db_name="xxxx"; // Database name
- $tbl_name="xxxx"; // Table name
- // Connect to server and select databse.
- $con = new mysqli("$host", "$username", "$password","$db_name")or die("cannot connect");
- // Define $myusername and $mypassword
- $myusername=$_POST['myusername'];
- $mypassword=$_POST['mypassword'];
- // To protect MySQL injection (more detail about MySQL injection)
- $myusername = stripslashes($myusername);
- $mypassword = stripslashes($mypassword);
- $myusername = mysqli_real_escape_string($con , $myusername);
- $mypassword = mysqli_real_escape_string($con , $mypassword);
- $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
- $result=mysqli_query($con , $sql);
- // Mysql_num_row is counting table row
- $count=mysqli_num_rows($result);
- // If result matched $myusername and $mypassword, table row must be 1 row
- if($count==1){
- // Register $myusername, $mypassword and redirect to file "login_success.php"
- $_SESSION['myusername']= "$myusername";
- $_SESSION['mypassword']= "$mypassword";
- header("location:login_success.php");
- }
- else {
- echo "Wrong username or password!";
- }
- ob_end_flush();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement