Mailing List ID Issue
Posted: Fri Dec 30, 2011 6:12 pm
I created my own method of having someone enter in their email into a "mailing list" because tutorials I've followed to create a mailing list with php never worked for me. The code I created works with just the one row for emails in the db but when the email is entered into the database I want an ID associated with it. I tried adding a new row to my table in the database called ID with is an INT and autoincrement and primary key and then when I test the mailing list by entering an email, the email doesn't get registered into the database. When I delete the ID row and try entering an email, it works.. I'm not sure where I'm going wrong and I provided my code below so someone can help me with this. Also is there a way to echo all the emails from the database table? Thanks in advance.
connect2.php
mailinglist.php
form on menu.php page
connect2.php
Code: Select all
<?PHP
$error = "Problem Connecting to the database.";
$connect = mysql_connect("localhost", "mydbusername", "mydbpassword") or die($error);
mysql_select_db("db_name") or die($error);
?>
Code: Select all
<?PHP
require 'connect2.php';
$submit = $_POST['submit'];
// form data
$email = addslashes(strip_tags($_POST['email']));
if ($submit)
{
// open database
include 'connect2.php';
$emailcheck = mysql_query("SELECT email FROM mailinglist WHERE email='$email'");
$count = mysql_num_rows($emailcheck);
if ($email)
{
if ($count!=0)
{
echo "<div id='mailinglistmsg' class='mailingText4'>You're already subscribed.</div>";
}
else
{
// register user
$queryreg = mysql_query("INSERT INTO mailinglist VALUES ('$email')");
echo "<div id='mailinglistmsg' class='mailingText4'>You have been added to our mailing list</div>";
}
}
else
echo "<div id='mailinglistmsg' class='mailingText4'>Please enter your email address.</div>";
}
?>
Code: Select all
<form action='menu.php' method='POST'>
<span class="mailingText5">Join our mailing list: </span><input name="email" id="email" type="text" size="20" maxlength="40" class="mailingText2" title="Join our Mailing List" />
<input name="submit" type="submit" class="mailingText3" id="submit" value="GO" />
</form>