utinaeniduin Posted November 22, 2006 Share Posted November 22, 2006 hi i am trying to put a small form on my site so that users can sign up to receive my newsletter, however, i do not want to change the page, but rather i would like to have the form disappear and a thank you message appear. i think i have the right idea, but i am quite a noobie. this is the most code i have ever written from scratch.[code]<? if ($step="sub") {$DBHost="myhost";$DBUser="myusername";$DBPass="mypassword";$DBName="mydb";mysql_connect("$DBHost","$DBUser","$DBPass"); mysql_select_db("listserv"); $name = $_POST['name']; $email = $_POST['email']; $result=mysql_query("INSERT INTO listserv (name,email)". "VALUES ('$name', '$email')"); echo " Join the Mailing List </div></td></tr><tr> <td height='70'><div align='center'> You have been added to the list.";} else {echo " Join the Mailing List </div></td></tr> <tr> <td height='70'><div align='center'> <form name='form1' method='post' action='?step=sub'> <p style='line-height: 22pt;'> <input name='name' type='text' class='input' id='name' value='Name'> <input name='email' type='text' class='input' id='email' value='Email'></p> <p style='line-height: 22pt;'> <input name='Submit' type='submit' class='button' value='Submit'></p> </form>";}?>[/code] Link to comment https://forums.phpfreaks.com/topic/28065-mailing-list-help/ Share on other sites More sharing options...
Vikas Jayna Posted November 22, 2006 Share Posted November 22, 2006 replace the line[code]if ($step="sub")[/code]with[code]if ($step=="sub")[/code]Basically, for comparison the operator is == and not = Link to comment https://forums.phpfreaks.com/topic/28065-mailing-list-help/#findComment-128401 Share on other sites More sharing options...
alpine Posted November 22, 2006 Share Posted November 22, 2006 still, this is not a needed detection - simply check if the submit button is posted:if(isset($_POST['Submit'])){// form is posted}You should also check that the fields is not left empty and secure your posted variables using for example mysql_real_escape_string, strip_tags, htmlspecialchars('',ENT_QUOTES) before allowing the query. Link to comment https://forums.phpfreaks.com/topic/28065-mailing-list-help/#findComment-128403 Share on other sites More sharing options...
utinaeniduin Posted November 22, 2006 Author Share Posted November 22, 2006 thanks vikas! Link to comment https://forums.phpfreaks.com/topic/28065-mailing-list-help/#findComment-128405 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.