I have this code selecting a combined e-mail and password but when I recall the e-mail using a login form the code fails and give me this error:
Fatal error: Uncaught exception 'PDOException' with message '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 '@gmail.com = 'admin'' at line 1' in C:\wamp\www\PWS\index.php on line 15
( ! ) PDOException: 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 '@gmail.com = 'admin'' at line 1 in C:\wamp\www\PWS\index.php on line 15'
I know why this isn't working though it recognizes the E-mail as a value Thodor20@gmail.com where @gmail.com is seperated because of the @. So how can I change the existing code:
<?php
include("connect.php");
$logemail = @$_POST['email'];
$logww = @$_POST['wachtwoord'];
if(isset($_POST['submit'])){
$q2 = $db->prepare("SELECT * FROM userinfo WHERE $logemail = '$logww'");
$q2->execute(array(':email'=>$logemail,':wachtwoord'=>$logww));
echo "Login succesvol!";
}
?>
And the form:
<form method="post">
E-mail:<input type="text" name="email"><br>
Wachtwoord:<input type="password" name="wachtwoord"><br>
<input type="submit" name="submit" value="Inloggen"><br>
</form>
So it will accept Thodor20@gmail.com as 1 full value and not in parts?
$q2 = $db->prepare("SELECT * FROM userinfo WHERE logemail = :email");
When using prepared statements you can use question marks or named placeholders ie :email
Also you may want to add another where
to select where logemail = :email and Wachtwoord = : Wachtwoord
I think you are using wordpress. I dont know exact syntax for wordpress query. But here you have syntax error
in your select
query.
Remove $
from $logemail
after WHERE
clause -
$q2 = $db->prepare("SELECT * FROM userinfo WHERE logemail = '$logemail'");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.