Advertisement
Guest User

Untitled

a guest
Dec 5th, 2016
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. Fatal error: Uncaught Error: Call to undefined function mysqli_connect() in /data/dbconnect.php:12
  2. Stack trace:
  3. 0 /data/index.php(4): require_once()
  4. 1 {main}
  5. thrown in /data/dbconnect.php on line 12
  6.  
  7. <?php
  8.  
  9. // this will avoid mysql_connect() deprecation error.
  10. error_reporting( ~E_DEPRECATED & ~E_NOTICE );
  11. // but I strongly suggest you to use PDO or MySQLi.
  12.  
  13. $dbHost = 'localhost';
  14. $dbUsername = 'root';
  15. $dbPassword = '';
  16. $dbName = 'phpmyadmin';
  17.  
  18. $conn = mysqli_connect($dbHost, $dbUsername, $dbPassword, $dbName);
  19. $dbcon = mysqli_select_db($dbName);
  20.  
  21. if ( !$conn ) {
  22. die("Connection failed : " . mysqli_error());
  23. }
  24.  
  25. if ( !$dbcon ) {
  26. die("Database Connection failed : " . mysqli_error());
  27. }
  28.  
  29. $db = new mysqli($dbHost, $dbUsername, $dbPassword, $dbName);
  30.  
  31. if ($db->connect_error) {
  32. die("Connection failed: " . $db->connect_error);
  33. }
  34. ?>
  35.  
  36. <?php
  37. ob_start();
  38. session_start(); // Starts the session
  39. require_once 'dbconnect.php';// Import the file "dbconnect.php" which is the connection of project with the database
  40.  
  41. if ( isset($_SESSION['user'])!="" ) { // It will never let you open index(login) page if you are logged in
  42. header("Location: home.php"); // Automatic send to home.php and blocking index page.
  43. exit;
  44. }
  45.  
  46. $error = false;
  47.  
  48. if( isset($_POST['btn-login']) ) {
  49.  
  50. // Prevent sql injections (attacks) / clear user invalid inputs
  51. $email = trim($_POST['email']);
  52. $email = strip_tags($email);
  53. $email = htmlspecialchars($email);
  54.  
  55. $pass = trim($_POST['pass']);
  56. $pass = strip_tags($pass);
  57. $pass = htmlspecialchars($pass);
  58. // Prevent sql injections (attacks) / clear user invalid inputs
  59.  
  60. // If there's no error this code allows the user to log in:
  61. if (!$error) {
  62.  
  63. $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;
  64. $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
  65. $row=mysql_fetch_array($res); // $row = mysql_fetch_array($res)it is returning the row
  66. $count = mysql_num_rows($res); // If the mail and password correct, it will return only one row
  67.  
  68. 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) -
  69. $_SESSION['user'] = $row['userId'];
  70. header("Location: home.php"); // - header("Location: home.php"); moves the user to the home.php just if the users data is correct
  71. } else {
  72. $errMSG = "Incorrect Credentials, Try again..."; // returning error if anything goes wrong.
  73. }
  74.  
  75. }
  76.  
  77. }
  78. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement