Jump to content

Adding info to MySQL database - help needed!


JoshuaV

Recommended Posts

Hello,

 

I'm trying to make users confirm their desire to enroll in a newsletter I am running. Right now after signing up they receive an email with a link that says "Click here to confirm!"

 

I can embed their email address into the link (like http://www.myserver.com/confirm.php?EMAIL).

 

I need a way so that just clicking on that URL adds that variable (their email address) into a MySQL database on my server. That way I'll have a complete list of confirmed subscribers in one database.

 

I'm a complete noob when it comes to PHP, so if someone could outline exactly what to do for me, I'd be eternally grateful.

 

Thanks a bunch!

<?php

   $email = mysql_escape_string($_GET['email']);

   if(isset($email))
   {
         $link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password');
          if (!$link) {
                          die('Could not connect: ' . mysql_error());
                       }

          $sql = "INSERT INTO table_name (email)
                    VALUES ('$email')";
          $result = mysql_query($sql);

           if(mysql_affected_rows($result) >= 1)
           {
                echo "email added";
             }
          
   }
?>

 

not tested just knocked it together in the fourm text entry bit so might have some errors but is basic gist of what you need to do

"Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in /home/content/c/l/e/cleanupthat/html/confirmed.php on line 16"

 

 

Line 16 is:

 

          if(mysql_affected_rows($result) >= 1)

 

Any clues?

 

Thanks so much guys.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.