Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function checklogin($email, $password){
- try
- {
- // Connection
- $conn;
- include_once('connect.php');
- // Build Query
- $sql = 'SELECT pkUserID, Email, Password, fkUserGroupID FROM tbluser WHERE Email = :email AND Password = :password';
- // $sql = 'SELECT pkUserID, Email, Password, fkUserGroupID FROM tbluser WHERE Email = "a" AND Password = "a"';
- // Prepare the SQL statement.
- $stmt = $conn->prepare($sql);
- // Add the value to the SQL statement
- $stmt->bindParam(':email', $email, PDO::PARAM_STR);
- $stmt->bindParam(':password', $password, PDO::PARAM_STR);
- // Execute SQL
- $stmt->execute();
- // Get the data in the result object
- $result = $stmt->fetchAll(); // $result is NULL always...
- // echo $stmt->rowCount(); // rowCount is always ZERO....
- // Check that we have some data
- if ($result != null)
- {
- // Start session
- if (session_status() == PHP_SESSION_NONE) {
- session_start();
- }
- // Search the results
- foreach($result as $row){
- // Set global environment variables with the key fields required
- $_SESSION['UserID'] = $row['pkUserID'];
- $_SESSION['Email'] = $row['Email'];
- }
- echo 'yippee';
- // Return empty string
- return '';
- }
- else {
- // Failed login
- return 'Login unsuccessful!';
- }
- $conn = null;
- }
- catch (PDOexception $e)
- {
- return 'Login failed: ' . $e->getMessage();
- }
- }
- <?php
- $servername = 'localhost';
- $username = 'admin';
- $password = 'password';
- try {
- // Change this line to connect to different database
- // Also enable the extension in the php.ini for new database engine.
- $conn = new PDO('mysql:host=localhost;dbname=processfgi', $username, $password);
- // set the PDO error mode to exception
- $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- // echo 'Connected successfully';
- }
- catch(PDOException $e)
- {
- echo 'Connection failed: ' . $e->getMessage();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement