Jump to content

enhanced08

Members
  • Posts

    5
  • Joined

  • Last visited

    Never

About enhanced08

  • Birthday 01/18/1987

Contact Methods

  • AIM
    spider10002
  • MSN
    mr_spider_@hotmail.com
  • Website URL
    http://www.fah-database.com

Profile Information

  • Gender
    Not Telling

enhanced08's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Alright, I will remove it. Thank you both very much, Im sure Ill be back asking more questions in the future.
  2. Ok, that does make sense and is much easier than what I was trying to do. One question I do have, it may not be directly related, however, is what exactly is/does the "0" do here: $sql=mysql_query($query, 0); I know I have that in my original code but thats because someone else told me I need it, Im just not sure what it is for.
  3. Ive been having this problem for awhile. Basically what I want to do is a mailing list. I want to have a user enter an email address and have it added to a database. i want a script that will check for an input (to make sure they dont hit submit before they type anything), check to make sure the data is an email address, and query the database to see if it is already there. I was able to get the data verification and email verification to work but I can not get it to check the database. I have tried and tried, Im no pro at PHP by any means and am learning as I go. Can someone tell me what Im doing wrong? I thought this was going to be simple. Here is my code: <? $db_user="**********"; $db_pass="**********"; $database="**********"; $host="**************"; $sent_email=$_POST['email']; $sent_email=strtolower($sent_email); $error='';//initialize $error to blank mysql_connect($host, $db_user, $db_pass); @mysql_select_db($database) or die( "Unable to select database"); if(trim($sent_email)==''){ $error="An email address is required!<br />"; } else { $query="SELECT * FROM mailing_list WHERE email=$sent_email"; $result=mysql_query($query, 0) or die(mysql_error()); if($result==$sent_email){ $error="Your email address is already in our database.<br />"; } else { if(!preg_match('/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/', $_POST['email'])) { $error="<p>The e-mail you entered was not in the proper format!<br><br> Try again.<br> <form action=mailing_list_add.php method=post accept-charset=utf-8> <table border=0 cellspacing=2 cellpadding=0> <tr><th>Email</th><td><input type=text name=email class=text></td></tr> </td></tr> <tr><td class=submission colspan=2><input type=submit name=s value=Submit></td></tr> </table> </form>"; } } } if($error==''){ { $query="INSERT INTO mailing_list VALUES ('','$sent_email')"; mysql_query($query); mysql_close(); } //echo "<script type=\"text/javascript\"> window.location = \"thankyou2.htm\"</script>"; } else{ echo "<span style=color:red>$error</span>"; } ?>
  4. Made the change, thanks. I did see on php.net that eregi was depricated but I did not write the code and was not sure what to use in place of it. I get an error with this. If I remove the 0 then it works but will not check the database for matches. WOW! I had no idea, thats good to know. thanks!
  5. what i have is a database setup for users to submit an email address for a mailing list. i want to be able to verify that an email has been entered rather than blank text, that it is in the correct format and that it is not already in the database. i used some code i found online and tried to modify it to fit my needs but am having problems. i know its a simple solution but its been about 5 years since i did any php work, and i wasnt very good back then. help, please? $db_user="*********"; $db_pass="**************"; $database="************"; $host="*******************"; $email=$_POST['email']; $email=strtolower($email); $error='';//initialize $error to blank mysql_connect($host, $db_user, $db_pass); @mysql_select_db($database) or die( "Unable to select database"); if(trim($_POST)==''){ $error.="An email address is required!<br />"; } else { $query="SELECT * FROM mailing_list WHERE email='$email'"; $result=mysql_query($query); if($result=='$email') { $error="Your email address is already in our database."; } else { if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST)) { $error="<p>The e-mail you entered was not in the proper format!<br><br> Try again.<br> <form action=mailing_list_add.php method=post accept-charset=utf-8> <table border=0 cellspacing=2 cellpadding=0> <tr><th>Email</th><td><input type=text name=email class=text></td></tr> </td></tr> <tr><td class=submission colspan=2><input type=submit name=s value=Submit></td></tr> </table> </form>"; } } } if($error==''){//Hmmmm no text is in $error so do something else, the page has verified and the email was valid // so uncomment the line below to send the user to your own success page or wherever (swap yourpage.php with your files location). { $query="INSERT INTO mailing_list VALUES ('','$email')"; mysql_query($query); mysql_close(); } echo "<script type=\"text/javascript\"> window.location = \"thankyou2.htm\"</script>"; } else{ echo "<span style=color:red>$error</span>"; } ?>
×
×
  • 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.