Matching an email address in mysql (php) not working - from paypal ipn
Having a noob day.
For some reason this works:
// check for user in db
$result = $connector->query('SELECT username FROM wallart_users
WHERE username ="test@testmail.com");
if (mysql_num_rows($result) == 0) {
////// ADD NEW USER
But this doesn't:
$payer_email = mysql_real_escape_string($payer_email);
// check for user in db
$result = $connector->query('SELECT username FROM wallart_users
WHERE username ='.$payer_email);
if (mysql_num_rows($result) == 0) {
////// NEW USER
The first one matches and sends me further down the page.
The second one doesn't match (with or without the escape) and tries to create a new user with the same c开发者_JAVA技巧redentials (then fails as the user already exists). The email address PayPal is sending is always the same, and the database contains the right address. I have written both addresses to a log file during the process and they look identical.'SELECT username FROM wallart_users WHERE username ="'.$payer_email.'"';
This code
$result = $connector->query('SELECT username FROM wallart_users
WHERE username ='.$payer_email);
Should be
$result = $connector->query("SELECT username FROM wallart_users
WHERE username ='$payer_email' ");
Do you not think that you are doing some thing wrong with your second query? you should change your query like this
$result = $connector->query('SELECT username FROM wallart_users WHERE username ="'.$payer_email.'"');
精彩评论