frijole Posted February 1, 2008 Share Posted February 1, 2008 I am trying to get a list of emails by having people enter their email into a text box and then send a SQL query to insert the email into the DB. I am not getting any PHP errors anymore. When i submit an email there is simply a blank page, and nothing in the DB. <?php /*Program: email.php *Desc: PHP program that sends an email address to the DB for a mailing list. */ if(ini_get("magic_quotes_gpc") == "1") { $_POST['email'] = stripslashes($_POST['email']); } $host="localhost"; $user="removed"; $password="removed"; if(!empty($_POST['form'])) { mysql_connect($host,$user,$password); mysql_select_db(thinksna_email); $result = mysql_query($_POST['email']); if($result == false) { echo "<h4>Error: ".mysql_error($cxn)."</h4>"; } else { $email = $_POST['email']; mysql_query("INSERT INTO email (email, email_id, dateTime) VALUES ('$email', '' , NOW())") or die(mysql_error()); echo "'$email' was added to the list"; } ?> And here is the HTML page that displays the form: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xml:lang="en"> <meta http-equiv="Content-Type" content="text/html"; charset="UTF-8" /> <head> <title>mypage.com</title> <link rel="stylesheet" type="text/css" href="web.css"> <link rel="Shortcut Icon" type="image" href="favicon.ico"> </head> <body> <form action="email.php" method="POST"> <input type="text" email="email"> <input type="submit" value="add my e-mail"> </form> </body> </html> im not sure what to do because of the lack of errors. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted February 1, 2008 Share Posted February 1, 2008 First glance I notice you are missing a close } at the end of the PHP script Quote Link to comment Share on other sites More sharing options...
frijole Posted February 1, 2008 Author Share Posted February 1, 2008 sorry, that was a copy and paste error. the "}" is there and the php script seems to execute i.e. no errors Quote Link to comment Share on other sites More sharing options...
rhodesa Posted February 1, 2008 Share Posted February 1, 2008 if(!empty($_POST['form'])) Also, the above will never be true. Use something like this instead: if(strlen($_POST['email'])) Furthermore, this line is random and should be removed: $result = mysql_query($_POST['email']); Quote Link to comment Share on other sites More sharing options...
frijole Posted February 1, 2008 Author Share Posted February 1, 2008 thanks ill give that a try. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted February 1, 2008 Share Posted February 1, 2008 More fixes... I assume mysql_select_db(thinksna_email); should be mysql_select_db('thinksna_email'); And to be safe, this line $email = $_POST['email']; should be $email = mysql_real_escape_string($_POST['email']); Quote Link to comment Share on other sites More sharing options...
avo Posted February 1, 2008 Share Posted February 1, 2008 Hi Try this <?php /*Program: email.php *Desc: PHP program that sends an email address to the DB for a mailing list. */ if(ini_get("magic_quotes_gpc") == "1") { $email = stripslashes($_POST['email']); } else { $email = $_POST['email']; } $host="localhost"; $user="removed"; $password="removed"; if(!empty($_POST['email'])) { $con = mysql_connect($host,$user,$password); $sel = mysql_select_db('thinksna_email'); //$result = mysql_query($_POST['email']); if(!$con) { echo "<h4>Error: ".mysql_error($cxn)."</h4>"; } else { mysql_query("INSERT INTO email (email, email_id, dateTime) VALUES ('$email', '' , NOW())") or die(mysql_error()); echo "$email was added to the list"; } } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.