JoshuaV Posted June 27, 2009 Share Posted June 27, 2009 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! Link to comment https://forums.phpfreaks.com/topic/163872-adding-info-to-mysql-database-help-needed/ Share on other sites More sharing options...
SetToLoki Posted June 27, 2009 Share Posted June 27, 2009 <?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 Link to comment https://forums.phpfreaks.com/topic/163872-adding-info-to-mysql-database-help-needed/#findComment-864618 Share on other sites More sharing options...
JoshuaV Posted June 27, 2009 Author Share Posted June 27, 2009 Ill give it a try, thanks a bunch!! Link to comment https://forums.phpfreaks.com/topic/163872-adding-info-to-mysql-database-help-needed/#findComment-864621 Share on other sites More sharing options...
JoshuaV Posted June 27, 2009 Author Share Posted June 27, 2009 "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. Link to comment https://forums.phpfreaks.com/topic/163872-adding-info-to-mysql-database-help-needed/#findComment-864625 Share on other sites More sharing options...
trq Posted June 27, 2009 Share Posted June 27, 2009 Your query is failing, try.... if ($result = mysql_query($sql)) { if (mysql_affected_rows($result) >= 1) { echo "email added"; } } else { echo mysql_error() . $sql; } Link to comment https://forums.phpfreaks.com/topic/163872-adding-info-to-mysql-database-help-needed/#findComment-864629 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.