phill2000star Posted December 2, 2006 Share Posted December 2, 2006 Hiya all,I am writing a script at the moment that basically checks an email address isn't already stored in a MySQL DB before adding it. I am getting stuck though and can't see why. Can anyone help me??Here's the code.=================================[code]$userExists = false;// open DB connectioninclude '../db/config.php';include '../db/dbOpen.php';$sql = "SELECT id, email FROM tbl_mailing_list WHERE email=$email";$result = mysql_query($sql);if (!$result) { echo "Could not successfully run query ($sql) from DB: " . mysql_error(); exit;}if (mysql_num_rows($result) == 0) { echo "No rows found, nothing to print so am exiting"; exit;}[/code]=================================Now when I submit an email address e.g. [email protected] to the script and an email address already exists, I get the following error.[b]Could not successfully run query (SELECT id, email FROM tbl_mailing_list WHERE [email protected]) from DB: 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 '@somedomain.net' at line 1[/b]Now if I was to remove the section of SQL "WHERE email=$email" and replace it with "WHERE email='[email protected]'" then it works perfectly!!Im pulling my last strand of hair out as I type!! Link to comment https://forums.phpfreaks.com/topic/29256-problem-searching-for-email-address-in-table/ Share on other sites More sharing options...
artacus Posted December 2, 2006 Share Posted December 2, 2006 quote your strings.[code] "SELECT ... WHERE email='$email'";[/code] Link to comment https://forums.phpfreaks.com/topic/29256-problem-searching-for-email-address-in-table/#findComment-134098 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.