Jump to content

why doesnt this work


dezkit

Recommended Posts

<?php
$ip = $_SERVER['REMOTE_ADDR'];
?>

<form name=index action=newsletter.php method=post>
Email: <td><input type=text name=email>
<input type=hidden name=ip value='<?php echo $ip ?>'>
<input type=submit value='Submit'>
</form>

 

 

<?php
$host = localhost
$dbuser = mysql_user
$dbpass = mysql_pass
$dbname = database_name

$connection = mysql_connect($host,$dbuser,$dbpass);
$db = mysql_select_db($dbname,$connection);

$email = $_POST['email'];
$ip = $_POST['ip'];

if($email == false){
echo "Please fill in your email";
};

$connection = mysql_connect($host,$dbuser,$dbpass);
$db = mysql_select_db($dbname,$connection);
$sql = "INSERT INTO newsletter (email,ip) VALUES ($email, $ip)";
$result = mysql_query($sql);
echo "Thank you for your registration.";
};

?>

 

CREATE TABLE `user` (
`email` varchar(40) NOT NULL default '',
`ip` varchar(20) NOT NULL default '',
PRIMARY KEY (`email`)
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; 

 

i want to do a newsletter for my website where i have an admin.php (i am working on it now) where i can go into it, login and send email to whoever signed up for the newsletter. i havent EVER used mysql or php in my life,  i took some codes from tutorials and i used my brain for prior knowledge, does anybody know what should i did wrong? i get a blank page whenever i type in my email address and press submit

Link to comment
Share on other sites

First of all you are connecting twice.  Get rid of the the second of this:

 

$connection = mysql_connect($host,$dbuser,$dbpass);

$db = mysql_select_db($dbname,$connection);

 

Second, echo the variables to make sure they are not blank.

Third, you need to add an ELSE in there like this.

 

if($email == false){
echo "Please fill in your email";
};
else
{
$connection = mysql_connect($host,$dbuser,$dbpass);
$db = mysql_select_db($dbname,$connection);
$sql = "INSERT INTO newsletter (email,ip) VALUES ($email, $ip)";
$result = mysql_query($sql);
echo "Thank you for your registration.";
};

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.