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!
Moderator: General Moderators
ebgames56
Forum Contributor
Posts: 103 Joined: Thu Oct 06, 2011 10:43 am
Post
by ebgames56 » Thu Oct 06, 2011 10:45 am
I have a issue with my subscribe.php
i want when a email is typed in the text box to put the email in the database
though it isnt going there, here is the code
Code: Select all
<?php
if(isset($_POST['add'])){
require_once('mysqlCreds.php');
$email = $_POST['email'];
if($email == ''){
header('Refresh: 5; url=http://szeryk.com/homepage');
echo "<div style='color: #FFFFFF;'>Please enter an email address to subscribe.</div><br />";
echo "<div style='color: #FFFFFF;'>If you aren't re-dreicted in a few seconds please click <a href='http://szeryk.com/homepage'>here</a></div>";
}
$result = mysql_query("SELECT * FROM emailList WHERE email='$email' LIMIT 1")or die(mysql_error());
while($row = mysql_fetch_array($result)){
if($row['email'] == $email){
header('Refresh: 5; url=http://szeryk.com/homepage');
echo "<div style='color: #FFFFFF;'>We are sorry, but this Email address is already subscribed.</div><br />";
echo "<div style='color: #FFFFFF;'>If you aren't re-dreicted in a few seconds please click <a href='http://szeryk.com/homepage/'>here</a></div>";
mysql_query("INSERT INTO emailList (id, email) VALUES('', '$email') ")or die(mysql_error());
header('Refresh: 5; url=http://szeryk.com/homepage');
echo "<div style='color: #FFFFFF;'>Thank you for subscribing to the newsleter!</div>";
echo "<br />";
echo "<div style='color: #FFFFFF;'>If you aren't re-dreicted in a few seconds please click <a href='http://szeryk.com/homepage'>here</a></div>"; }
}
}
?>
though if you can help me i will pay you BIG TIME
if you can use teamviewer add me on msn
therealmattbrown@hotmail.com
thanks
Celauran
Moderator
Posts: 6427 Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada
Post
by Celauran » Thu Oct 06, 2011 10:52 am
Is emailList.email a unique field? You're trying to insert only when the email already exists.
ebgames56
Forum Contributor
Posts: 103 Joined: Thu Oct 06, 2011 10:43 am
Post
by ebgames56 » Thu Oct 06, 2011 10:54 am
can you add me on msn
Celauran
Moderator
Posts: 6427 Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada
Post
by Celauran » Thu Oct 06, 2011 11:00 am
Celauran wrote: Is emailList.email a unique field? You're trying to insert only when the email already exists.
ebgames56
Forum Contributor
Posts: 103 Joined: Thu Oct 06, 2011 10:43 am
Post
by ebgames56 » Thu Oct 06, 2011 11:03 am
i have a database called sszeryk_newsLetter and in it i have 3 tables emailList, emailVol, users. but you only have to worrie about emailList
ebgames56
Forum Contributor
Posts: 103 Joined: Thu Oct 06, 2011 10:43 am
Post
by ebgames56 » Thu Oct 06, 2011 11:05 am
ya that happens to when i put a email that is already in the database in the text box it only gets re added to the database but that message doesnt show "this email address is already subscribed"
Celauran
Moderator
Posts: 6427 Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada
Post
by Celauran » Thu Oct 06, 2011 11:12 am
Ignoring the redirects for a minute, does this work?
Code: Select all
<?php
if (isset($_POST['add']))
{
require_once('mysqlCreds.php');
$email = $_POST['email'];
if ($email == '')
{
header('Refresh: 5; url=http://szeryk.com/homepage');
echo "<div style='color: #FFFFFF;'>Please enter an email address to subscribe.</div>";
echo "<div style='color: #FFFFFF;'>If you aren't re-dreicted in a few seconds please click <a href='http://szeryk.com/homepage'>here</a></div>";
}
$result = mysql_query("SELECT * FROM emailList WHERE email='$email' LIMIT 1") or die(mysql_error());
while ($row = mysql_fetch_array($result))
{
if ($row['email'] == $email)
{
echo "<div style='color: #FFFFFF;'>We are sorry, but this Email address is already subscribed.</div>";
}
else
{
$query = "INSERT INTO emailList (id, email) VALUES('', '$email') ";
mysql_query($query) or die(mysql_error());
echo "<div style='color: #FFFFFF;'>Thank you for subscribing to the newsleter!</div>";
}
}
}
?>
ebgames56
Forum Contributor
Posts: 103 Joined: Thu Oct 06, 2011 10:43 am
Post
by ebgames56 » Thu Oct 06, 2011 11:19 am
yea it does but, when i put a email in that isnt in the database it just shows black blank nothing there
Celauran
Moderator
Posts: 6427 Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada
Post
by Celauran » Thu Oct 06, 2011 11:20 am
Does the database get updated with the new email?
ebgames56
Forum Contributor
Posts: 103 Joined: Thu Oct 06, 2011 10:43 am
Post
by ebgames56 » Thu Oct 06, 2011 12:22 pm
no it doesnt
ebgames56
Forum Contributor
Posts: 103 Joined: Thu Oct 06, 2011 10:43 am
Post
by ebgames56 » Thu Oct 06, 2011 12:46 pm
Celauran wrote: Does the database get updated with the new email?
no it doesnt
Celauran
Moderator
Posts: 6427 Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada
Post
by Celauran » Thu Oct 06, 2011 1:05 pm
And if you echo $query?
ebgames56
Forum Contributor
Posts: 103 Joined: Thu Oct 06, 2011 10:43 am
Post
by ebgames56 » Thu Oct 06, 2011 1:06 pm
yes im echoing query
Celauran
Moderator
Posts: 6427 Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada
Post
by Celauran » Thu Oct 06, 2011 1:08 pm
What output is displayed when you echo $query is what I'm asking.