Question

I am having trouble getting this to work I will include the code both working and what I am trying to accomplish. In the first code it is non-working and gives me an error message: Connection failed: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':userName ANDpassword=:userPass' at line 1 I have tried several different combinations of syntax and still no luck. In the second code example it is working code and basically I am trying to get rid of all the unnecessary code to just obtain a $row count from the function to verify that there was 1 row that matched the query.

function checkLogin($conn,$myusername, $mypassword) {

       $stmt = $conn->prepare('SELECT COUNT(*) FROM `CLL_users` WHERE `user_name`= :userName AND `password`= :userPass');
       $stmt->bindValue(':userName', $myusername);
       $stmt->bindValue(':userPass', $mypassword);
       $stmt->execute();
       $count = $stmt->fetchColumn();
       return $count;
}
Was it helpful?

Solution

function checkLogin($conn,$myusername, $mypassword) {

           $stmt = $conn->prepare('SELECT COUNT(*) FROM `CLL_users` WHERE `user_name`= :userName AND `password`= :userPass');
           $stmt->bindValue(':userName', $myusername);
           $stmt->bindValue(':userPass', $mypassword);
           $stmt->execute();
           $count = $stmt->fetchColumn();
           return $count;
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top