Jump to content

Always an error when it comes to email addresses...


maxudaskin

Recommended Posts

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: someemail@hosturl.com";
         }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 ('emailaddress@email.com','2008/03/26 20:54:07','' at line 1

 

upl9872840689.jpg

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.