Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include ('condb.php');//connect to the database and check connection.
- // assign the variable.
- $email=mysqli_real_escape_string($conn, $_POST['email']);// accept the data with mysqli_real_escape_string() function.
- $password=mysqli_real_escape_string($conn,md5($_POST['password']));//save password with md5 function for security reason.
- // check the data with javascript alert function
- if ($email==''){// check yourname is empty or not by using javascript alert.
- echo "<script>alert('Enter your email')</script>";// give error message
- exit();// if data input field is empty stop here and don't go anyfuther.
- }
- $query="SELECT name
- FROM users
- 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.
- $result=mysqli_query($conn,$query);// make connection and process query.
- $row=mysqli_fetch_array($result,MYSQLI_ASSOC);//mysqli_fetch_array ()fuction fetch a result row as numberic arry and associative array
- // check the userinput data
- 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.
- {
- echo $message = $row['name']." Login Sucessfully!!";//show name and give message
- header('Location:homepage.php');//link to the homepage.php
- }
- else
- {
- echo $message = "Invalid email or password!!";// other wise give error message.
- exit();
- }
- mysqli_close($conn);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement