dezkit Posted March 29, 2008 Share Posted March 29, 2008 <?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 Quote Link to comment Share on other sites More sharing options...
Steve Angelis Posted March 29, 2008 Share Posted March 29, 2008 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."; }; Quote Link to comment Share on other sites More sharing options...
maexus Posted March 29, 2008 Share Posted March 29, 2008 You are missing some ; <input type=hidden name=ip value='<?php echo $ip; ?>'> $host = localhost; $dbuser = mysql_user; $dbpass = mysql_pass; $dbname = database_name; Quote Link to comment Share on other sites More sharing options...
dezkit Posted March 29, 2008 Author Share Posted March 29, 2008 ughh i fixed those problems, thanks guys, but it still doesn't work i give up. i have absolutely no knowledge of mysql and a little knowledge of php. thanks again guys! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.