Database .php

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

Database .php

Post 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
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Database .php

Post by Celauran »

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

Re: Database .php

Post by ebgames56 »

can you add me on msn
ebgames56
Forum Contributor
Posts: 103
Joined: Thu Oct 06, 2011 10:43 am

Re: Database .php

Post by ebgames56 »

you can take a look what im trying to do with the newsletter http://szeryk.com/
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Database .php

Post by Celauran »

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

Re: Database .php

Post 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
ebgames56
Forum Contributor
Posts: 103
Joined: Thu Oct 06, 2011 10:43 am

Re: Database .php

Post 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"
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Database .php

Post 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>";
        }
    }
}
?>
ebgames56
Forum Contributor
Posts: 103
Joined: Thu Oct 06, 2011 10:43 am

Re: Database .php

Post by ebgames56 »

yea it does but, when i put a email in that isnt in the database it just shows black blank nothing there
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Database .php

Post by Celauran »

Does the database get updated with the new email?
ebgames56
Forum Contributor
Posts: 103
Joined: Thu Oct 06, 2011 10:43 am

Re: Database .php

Post by ebgames56 »

no it doesnt
ebgames56
Forum Contributor
Posts: 103
Joined: Thu Oct 06, 2011 10:43 am

Re: Database .php

Post by ebgames56 »

Celauran wrote:Does the database get updated with the new email?
no it doesnt
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Database .php

Post by Celauran »

And if you echo $query?
ebgames56
Forum Contributor
Posts: 103
Joined: Thu Oct 06, 2011 10:43 am

Re: Database .php

Post by ebgames56 »

yes im echoing query
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Database .php

Post by Celauran »

What output is displayed when you echo $query is what I'm asking.
Post Reply