Page 1 of 2

Database .php

Posted: Thu Oct 06, 2011 10:45 am
by ebgames56
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

Re: Database .php

Posted: Thu Oct 06, 2011 10:52 am
by Celauran
Is emailList.email a unique field? You're trying to insert only when the email already exists.

Re: Database .php

Posted: Thu Oct 06, 2011 10:54 am
by ebgames56
can you add me on msn

Re: Database .php

Posted: Thu Oct 06, 2011 10:55 am
by ebgames56
you can take a look what im trying to do with the newsletter http://szeryk.com/

Re: Database .php

Posted: Thu Oct 06, 2011 11:00 am
by Celauran
Celauran wrote:Is emailList.email a unique field? You're trying to insert only when the email already exists.

Re: Database .php

Posted: Thu Oct 06, 2011 11:03 am
by ebgames56
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

Re: Database .php

Posted: Thu Oct 06, 2011 11:05 am
by ebgames56
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"

Re: Database .php

Posted: Thu Oct 06, 2011 11:12 am
by Celauran
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>";
        }
    }
}
?>

Re: Database .php

Posted: Thu Oct 06, 2011 11:19 am
by ebgames56
yea it does but, when i put a email in that isnt in the database it just shows black blank nothing there

Re: Database .php

Posted: Thu Oct 06, 2011 11:20 am
by Celauran
Does the database get updated with the new email?

Re: Database .php

Posted: Thu Oct 06, 2011 12:22 pm
by ebgames56
no it doesnt

Re: Database .php

Posted: Thu Oct 06, 2011 12:46 pm
by ebgames56
Celauran wrote:Does the database get updated with the new email?
no it doesnt

Re: Database .php

Posted: Thu Oct 06, 2011 1:05 pm
by Celauran
And if you echo $query?

Re: Database .php

Posted: Thu Oct 06, 2011 1:06 pm
by ebgames56
yes im echoing query

Re: Database .php

Posted: Thu Oct 06, 2011 1:08 pm
by Celauran
What output is displayed when you echo $query is what I'm asking.