maxudaskin Posted March 26, 2008 Share Posted March 26, 2008 Basically, I made a script in 30 minutes, corrected the syntax errors in about 2, but now I am stuck on the MySQL error I got... <?php function subscribe (){ if($_GET['do'] == "unsubscribe"){ if(!empty($_GET['id'])){ $email = $_GET['email']; $query = mysql_query("SELECT * FROM dnh_subscribers WHERE email = '$email'") or die("MySQL Error: " . mysql_error()); if(mysql_num_rows($query) != 0){ mysql_query("DELETE FROM dnh_subscribers WHERE email = '$email'") or die("MySQL Error: " . mysql_error()); echo "Your email, " . $email . ",has been removed from the list."; }else{ echo "I am sorry, I cannot remove you from the subscriber list because either you have specified the wrong email or your email has already been removed."; } }else{ echo "We cannot unsubscribe you as you have not supplied an email."; } }else{ if(!empty($_POST['email'])){ $email = $_POST['email']; if(!filter_var($email, FILTER_VALIDATE_EMAIL)){ echo "ERROR: You did not input a correct email. The email must be formatted like this: [email protected]"; }else{ $query = mysql_query("SELECT * FROM dnh_subscribers WHERE email = '$email'"); if(mysql_num_rows($query) == 0){ $datetime = gmdate("Y/m/d H:i:s"); $ip = $_SERVER['REMOTE_ADDR']; mysql_query("INSERT INTO dnh_subscribers ('email','datetime','ip') VALUES ('$email','$datetime','$ip')") or die("MySQL Error: " . mysql_error()); // Error Here echo "Thank you for subscribing. When another person is added to the DNH list, you will automatically be notified."; }else{ $result = mysql_fetch_array($query); echo "Your email is already on the list, would you like to unsubscribe? "; echo "<a href=\"index.php?do=unsubscribe&email=" . $result['email'] . "\">Yes</a> <a href=\"index.php\">No</a>"; } } }else{ echo "<form action=\"" . $PHP_SELF . "\" method=\"post\">"; echo "<label>"; echo "<input name=\"email\" type=\"text\" id=\"email\">"; echo "</label>"; echo "<label>"; echo "<input type=\"submit\" name=\"Submit\" value=\"Subscribe to Updates\">"; echo "</label>"; echo "<span class=\"style1\">Your email will never be given to 3rd parties.</span>"; echo "</form>"; } } } ?> This function is called on another page (irrelevant). Error: 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 ''email','datetime','ip') VALUES ('[email protected]','2008/03/26 20:54:07','' at line 1 Link to comment https://forums.phpfreaks.com/topic/98046-always-an-error-when-it-comes-to-email-addresses/ Share on other sites More sharing options...
cooldude832 Posted March 26, 2008 Share Posted March 26, 2008 first off email should be varchar 256 not longtext secondly rewrite queries like <?php $q = "Select this from `that`"; $r = mysql_query($q) or die(mysql_error()."<br /><br />".$q); ?> and post the complete outputted $q error message. Link to comment https://forums.phpfreaks.com/topic/98046-always-an-error-when-it-comes-to-email-addresses/#findComment-501656 Share on other sites More sharing options...
maxudaskin Posted March 26, 2008 Author Share Posted March 26, 2008 The error is with Inserting... Two reasons how I know, only one Insert, two, the INSERT INTO is the only one with the email, datetime, and ip... Link to comment https://forums.phpfreaks.com/topic/98046-always-an-error-when-it-comes-to-email-addresses/#findComment-501659 Share on other sites More sharing options...
pocobueno1388 Posted March 26, 2008 Share Posted March 26, 2008 I don't think your supposed to put quotes around the field names. Try: INSERT INTO dnh_subscribers (email, datetime, ip) VALUES ('$email','$datetime','$ip') Link to comment https://forums.phpfreaks.com/topic/98046-always-an-error-when-it-comes-to-email-addresses/#findComment-501661 Share on other sites More sharing options...
cooldude832 Posted March 26, 2008 Share Posted March 26, 2008 The error is with Inserting... Two reasons how I know, only one Insert, two, the INSERT INTO is the only one with the email, datetime, and ip... I know where the error is, but without seeing what comes before it in the query its difficult to interpert the mysql_error mysql_error is designed to be used when you are looking at the query with it Link to comment https://forums.phpfreaks.com/topic/98046-always-an-error-when-it-comes-to-email-addresses/#findComment-501663 Share on other sites More sharing options...
maxudaskin Posted March 26, 2008 Author Share Posted March 26, 2008 Thank you. Link to comment https://forums.phpfreaks.com/topic/98046-always-an-error-when-it-comes-to-email-addresses/#findComment-501665 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.