Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start(); // Starting Session
- $error=''; // Variable To Store Error Message
- if (isset($_POST['submit'])) {
- if (empty($_POST['username']) || empty($_POST['password'])) {
- $error = "Username or Password is invalid";
- } else {
- // Selecting Database
- $mysqli = new mysqli("localhost", "root", "root");
- $mysqli->select_db('tasty_recipe') or die ($mysqli->error);
- $username = $mysqli->real_escape_string($_POST['username']);
- $password = $mysqli->real_escape_string($_POST['password']);
- // SQL query to fetch information of registerd users and finds user match.
- $sql = $mysqli->query("SELECT * FROM `user` WHERE password='$password' AND username='$username'") or die ($mysqli->error);
- if ($sql->num_rows == 1) {
- $data = $sql->fetch_assoc();
- $_SESSION['username'] = $data['username']; // Initializing Session
- header("location: profile.php"); // Redirecting To Other Page
- } else {
- echo $sql->num_rows;
- $error = "Username or Password is invalid";
- }
- mysqli_close($connection); // Closing Connection
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement