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
- {
- // Define $username and $password
- $username=$_POST['username'];
- $password=$_POST['password'];
- // Establishing Connection with Server by passing server_name, user_id and password as a parameter
- $servername = "localhost";
- $username = "root";
- $password = "";
- $dbname = "server1";
- // Create connection
- $conn = new mysqli($servername, $username, $password,$dbname);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- // To protect mysqli injection for Security purpose
- $username = stripslashes($username);
- $password = stripslashes($password);
- $username = mysqli_real_escape_string($username);
- $password = mysqli_real_escape_string($password);
- // Selecting Database
- $db = mysqli_select_db("server1", $conn);
- // SQL query to fetch information of registerd users and finds user match.
- $query = "select * from account where password='$password' AND username='$username'";
- $result = mysqli_query($conn, $query) or trigger_error("Query Failed! SQL: $query - Error: ". mysqli_error($mysqli), E_USER_ERROR);;
- $rows = mysqli_num_rows($query);
- if ($rows == 1) {
- $_SESSION['login_user']=$username; // Initializing Session
- header("location: profile.php"); // Redirecting To Other Page
- } else {
- $error = "Username or Password is invalid";
- }
- mysqli_close($conn); // Closing Connection
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement