PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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.
<?PHP
$error = "Problem Connecting to the database.";
$connect = mysql_connect("localhost", "mydbusername", "mydbpassword") or die($error);
mysql_select_db("db_name") or die($error);
?>
<?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>";
}
?>