Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Fatal error: Uncaught Error: Call to undefined function mysqli_connect() in /data/dbconnect.php:12
- Stack trace:
- 0 /data/index.php(4): require_once()
- 1 {main}
- thrown in /data/dbconnect.php on line 12
- <?php
- // this will avoid mysql_connect() deprecation error.
- error_reporting( ~E_DEPRECATED & ~E_NOTICE );
- // but I strongly suggest you to use PDO or MySQLi.
- $dbHost = 'localhost';
- $dbUsername = 'root';
- $dbPassword = '';
- $dbName = 'phpmyadmin';
- $conn = mysqli_connect($dbHost, $dbUsername, $dbPassword, $dbName);
- $dbcon = mysqli_select_db($dbName);
- if ( !$conn ) {
- die("Connection failed : " . mysqli_error());
- }
- if ( !$dbcon ) {
- die("Database Connection failed : " . mysqli_error());
- }
- $db = new mysqli($dbHost, $dbUsername, $dbPassword, $dbName);
- if ($db->connect_error) {
- die("Connection failed: " . $db->connect_error);
- }
- ?>
- <?php
- ob_start();
- session_start(); // Starts the session
- require_once 'dbconnect.php';// Import the file "dbconnect.php" which is the connection of project with the database
- if ( isset($_SESSION['user'])!="" ) { // It will never let you open index(login) page if you are logged in
- header("Location: home.php"); // Automatic send to home.php and blocking index page.
- exit;
- }
- $error = false;
- if( isset($_POST['btn-login']) ) {
- // Prevent sql injections (attacks) / clear user invalid inputs
- $email = trim($_POST['email']);
- $email = strip_tags($email);
- $email = htmlspecialchars($email);
- $pass = trim($_POST['pass']);
- $pass = strip_tags($pass);
- $pass = htmlspecialchars($pass);
- // Prevent sql injections (attacks) / clear user invalid inputs
- // If there's no error this code allows the user to log in:
- if (!$error) {
- $password = hash('sha256', $pass); // Password hashing using SHA256 it is encripting of the password that the user is entering so that third people cant read it, to check it do SELECT * FROM users;
- $res=mysql_query("SELECT userId, userName, userPass FROM users WHERE userEmail='$email'"); // Takes the data from the database where the userEmail is equal to the $email that has been inserted
- $row=mysql_fetch_array($res); // $row = mysql_fetch_array($res)it is returning the row
- $count = mysql_num_rows($res); // If the mail and password correct, it will return only one row
- if( $count == 1 && $row['userPass'] == $password ) { // it is taking the userPass and user Id for the session, if the data inserted during login is correct (rest of description line 50) -
- $_SESSION['user'] = $row['userId'];
- header("Location: home.php"); // - header("Location: home.php"); moves the user to the home.php just if the users data is correct
- } else {
- $errMSG = "Incorrect Credentials, Try again..."; // returning error if anything goes wrong.
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement