Jump to content

mailing list help


utinaeniduin

Recommended Posts

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

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

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.