Im having some problems trying to send mail to db, and the if arent correct... but im new and i dont have too much idea need some help please, first there are legal conditions to accept, then a email filter, and then must know if mail is in database already.
This is the code:
There are some comments that are previosly tryies, sorry about. Must say CONNECTING WITH DB IS NOT THE PROBLEM(I tryed it before putting some ifs), the problem is syntax i think... thanksPHP Code:<?php
$email = $_POST["email"];
// $search = "SELECT * FROM `[db]` WHERE `email` = '$email'";
// $result = mysql_query($search) or die ('Error');
// $num = mysql_num_rows($result);
if (isset($_POST['privacidad']))
{ $privacidad = '1';
echo"Terms accepted.";}
if ($seleccionado == '1') {
// Comprobar si el usuario introducido existe
$error.= "Check again:<br /><br />";
$checkuser = mysql_query("SELECT email FROM email WHERE email='$email'");
$username_exist = mysql_num_rows($checkuser);
if($username_exist > 0){
$error.= "- Already exists<br />";
}
//if(!$email == "" && (!strstr($email,"@") || !strstr($email,"."))) {
//Check mail
if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) { echo "";
} else {
echo "- Incorrect email. ";}
}
//$estat = "<h2>Not sent</h2>";
//echo $estat;
//die ("Go back!");
} else {
// if ($num != 0) {
// echo ("Email used"); }
// else {
mysql_connect('host' , 'user', 'pw');
mysql_select_db("dbname");
mysql_query("INSERT INTO email (email) VALUES ('$email')");
echo mysql_error();
echo 'email sent 222';
echo $email;
}
} else {
echo 'must accept legal terms';
alert ('must accept legal terms');
}




Reply With Quote