DBookatay Posted December 19, 2007 Share Posted December 19, 2007 I am trying to make a form on my site (http://www.carcityofdanbury.com/inventory.php?status=Error#StayUpdated) where a user enters their email address if they wish to recieve emails when my site is updated, but I'm obviously doing something incorrect, cause the script keeps failing. Can someone show/ tell me what is wrong? The HTML <table> <tr class="title225"><td height="23" style="padding-left:10px"><a id="StayUpdated"></a><span class="subTitle">Stay Updated</span></td></tr> <tr><td class="ContHldr"> <form action="inventory.php" name="form" method="post" class="no"> <div align="center"> <table> <tr><td class="frmPad">Want to say updated with all<br />the changes made on our site?</td></tr> <tr><td style="padding-top:10px"><? echo $update_errors ?><input name="updated" type="text" class="input" size="30" onclick="if(this.value=='Enter Email Address'){this.value=''}" value="Enter Email Address" /></td></tr> <tr><td align="center" style="padding-top:10px"><input type="image" src="images/Default/BTNs/signupOff.gif" srcover="images/Default/BTNs/signupOn.gif" name="submit" /></td></tr> </table> </div> </form> <tr><td><img src="images/Default/Titles/btm225.gif" /></td></tr> </table> The PHP: if(!(empty($_POST['updated']))) { if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})", $_POST['updated'])) { $email = $_POST['updated']; } else { $email = 'Enter Email Address'; } } if ($email == "Enter Email Address") { echo '<HEAD><SCRIPT language="JavaScript1.1">location.replace("inventory.php?status=Error#StayUpdated");</SCRIPT></HEAD>'; } else { $querySubmit; } $querySubmit = mysql_query("INSERT INTO RecieveUpdates (email) VALUES ('$email')")or die(mysql_error()); echo "<meta http-equiv=\"Refresh\" content=\"0; url=inventory.php?status=Good\">"; (I know that the code is much longer and hacked togather than it needs to be, but I am a self admitted "NOOB!") Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 19, 2007 Share Posted December 19, 2007 change if(!(empty($_POST['updated']))) { to if($_POST['updated'] != "") { Quote Link to comment Share on other sites More sharing options...
DBookatay Posted December 19, 2007 Author Share Posted December 19, 2007 change if(!(empty($_POST['updated']))) { to if($_POST['updated'] != "") { It still redirectes the user, as soon as the page loads, even if the submit button is not pressed Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 19, 2007 Share Posted December 19, 2007 oh my mistake then, i didnt know it was a button. use if(isset($_POST['updated'])){ if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})", $_POST['updated'])) { $email = $_POST['updated']; } else { $email = 'Enter Email Address'; } if ($email == "Enter Email Address") { echo '<HEAD><SCRIPT language="JavaScript1.1">location.replace("inventory.php?status=Error#StayUpdated");</SCRIPT></HEAD>'; } else { $querySubmit; } $querySubmit = mysql_query("INSERT INTO RecieveUpdates (email) VALUES ('$email')")or die(mysql_error()); echo "<meta http-equiv=\"Refresh\" content=\"0; url=inventory.php?status=Good\">"; } Quote Link to comment Share on other sites More sharing options...
DBookatay Posted December 19, 2007 Author Share Posted December 19, 2007 Ok, now the script is working, however it is still not 100%. Even if the user does not enter an email address, and the default "Enter Email Address" is in the field, it still inserts "Enter Email Address" into the dB, instead of blocking it with errors... Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 19, 2007 Share Posted December 19, 2007 try f(isset($_POST['updated'])){ if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})", $_POST['updated'])) { echo '<HEAD><SCRIPT language="JavaScript1.1">location.replace("inventory.php?status=Error#StayUpdated");</SCRIPT></HEAD>'; } else{ $email = $_POST['updated']; $querySubmit; $querySubmit = mysql_query("INSERT INTO RecieveUpdates (email) VALUES ('$email')")or die(mysql_error()); echo "<meta http-equiv=\"Refresh\" content=\"0; url=inventory.php?status=Good\">"; } } Quote Link to comment Share on other sites More sharing options...
DBookatay Posted December 19, 2007 Author Share Posted December 19, 2007 try f(isset($_POST['updated'])){ if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})", $_POST['updated'])) { echo '<HEAD><SCRIPT language="JavaScript1.1">location.replace("inventory.php?status=Error#StayUpdated");</SCRIPT></HEAD>'; } else{ $email = $_POST['updated']; $querySubmit; $querySubmit = mysql_query("INSERT INTO RecieveUpdates (email) VALUES ('$email')")or die(mysql_error()); echo "<meta http-equiv=\"Refresh\" content=\"0; url=inventory.php?status=Good\">"; } } Thats it, thanks... Quote Link to comment Share on other sites More sharing options...
DBookatay Posted December 19, 2007 Author Share Posted December 19, 2007 Looking at the script you created, leaves me with a question I always wondered. I used to use the redirect php script echo "<meta http-equiv="Refresh" content="0; url=inventory.php?status=Good"> but it seams like the java version <HEAD><SCRIPT language="JavaScript1.1">location.replace("inventory.php?status=Error#StayUpdated");</SCRIPT></HEAD> works much quicker. Anyone care to comment? Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 19, 2007 Share Posted December 19, 2007 I think that would lead to a lonnnnng convo on what is best to redirect a user. 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.