Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. function checklogin($email, $password){
  2. try
  3. {
  4. // Connection
  5. $conn;
  6. include_once('connect.php');
  7. // Build Query
  8. $sql = 'SELECT pkUserID, Email, Password, fkUserGroupID FROM tbluser WHERE Email = :email AND Password = :password';
  9. // $sql = 'SELECT pkUserID, Email, Password, fkUserGroupID FROM tbluser WHERE Email = "a" AND Password = "a"';
  10. // Prepare the SQL statement.
  11. $stmt = $conn->prepare($sql);
  12. // Add the value to the SQL statement
  13. $stmt->bindParam(':email', $email, PDO::PARAM_STR);
  14. $stmt->bindParam(':password', $password, PDO::PARAM_STR);
  15. // Execute SQL
  16. $stmt->execute();
  17. // Get the data in the result object
  18. $result = $stmt->fetchAll(); // $result is NULL always...
  19.  
  20. // echo $stmt->rowCount(); // rowCount is always ZERO....
  21.  
  22. // Check that we have some data
  23. if ($result != null)
  24. {
  25. // Start session
  26. if (session_status() == PHP_SESSION_NONE) {
  27. session_start();
  28. }
  29. // Search the results
  30. foreach($result as $row){
  31. // Set global environment variables with the key fields required
  32. $_SESSION['UserID'] = $row['pkUserID'];
  33. $_SESSION['Email'] = $row['Email'];
  34. }
  35. echo 'yippee';
  36. // Return empty string
  37. return '';
  38. }
  39. else {
  40. // Failed login
  41. return 'Login unsuccessful!';
  42. }
  43. $conn = null;
  44. }
  45. catch (PDOexception $e)
  46. {
  47. return 'Login failed: ' . $e->getMessage();
  48. }
  49. }
  50.  
  51. <?php
  52.  
  53.  
  54. $servername = 'localhost';
  55. $username = 'admin';
  56. $password = 'password';
  57.  
  58. try {
  59. // Change this line to connect to different database
  60. // Also enable the extension in the php.ini for new database engine.
  61. $conn = new PDO('mysql:host=localhost;dbname=processfgi', $username, $password);
  62. // set the PDO error mode to exception
  63. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  64. // echo 'Connected successfully';
  65. }
  66. catch(PDOException $e)
  67. {
  68. echo 'Connection failed: ' . $e->getMessage();
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement