Advertisement
Guest User

Untitled

a guest
Dec 17th, 2014
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. <?php
  2. include ('condb.php');//connect to the database and check connection.
  3.  
  4. // assign the variable.
  5. $email=mysqli_real_escape_string($conn, $_POST['email']);// accept the data with mysqli_real_escape_string() function.
  6. $password=mysqli_real_escape_string($conn,md5($_POST['password']));//save password with md5 function for security reason.
  7.  
  8. // check the data with javascript alert function
  9.  
  10. if ($email==''){// check yourname is empty or not by using javascript alert.
  11. echo "<script>alert('Enter your email')</script>";// give error message
  12. exit();// if data input field is empty stop here and don't go anyfuther.
  13. }
  14.  
  15. $query="SELECT name
  16. FROM users
  17. WHERE email= '$email' AND password= '$password' ";// select 'name' data from database call users where accept data email is same as the data in the database.
  18.  
  19.  
  20. $result=mysqli_query($conn,$query);// make connection and process query.
  21. $row=mysqli_fetch_array($result,MYSQLI_ASSOC);//mysqli_fetch_array ()fuction fetch a result row as numberic arry and associative array
  22.  
  23. // check the userinput data
  24.  
  25. if(count($row)>=1)//chech the result with if statement , if the data is there give error message or success ful login and show message.
  26. {
  27. echo $message = $row['name']." Login Sucessfully!!";//show name and give message
  28. header('Location:homepage.php');//link to the homepage.php
  29.  
  30.  
  31. }
  32. else
  33. {
  34. echo $message = "Invalid email or password!!";// other wise give error message.
  35. exit();
  36. }
  37.  
  38. mysqli_close($conn);
  39. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement