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
https://forums.phpfreaks.com/topic/98494-why-doesnt-this-work/
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
https://forums.phpfreaks.com/topic/98494-why-doesnt-this-work/#findComment-504063
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.