Jump to content

chasdrury

New Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

chasdrury's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks guys. I have inputted this into the insert.php script and it still doesn't work. It lets through any email, whether or not they are in the database. The only difference now is that I have put a unique identifier in the email list in the SQL, so the data isn't written to the database, but the people still get the auto email discount thing, since no error is kicked up. My PHP is below (I have copied in everything upto the start of the discount email) [code]<? $username="xxx"; $password="xxx"; $database="xxx"; $name=$_POST['requiredname']; $phone=$_POST['requiredphone']; $email=$_POST['requiredemail']; $from = "info@hairkandi.com"; $subject = "Hair Kandi Discount Voucher"; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $check = mysql_query("SELECT COUNT(*) FROM contacts WHERE email = '$email' "); if (mysql_result ($check, 0) > 0) {     // error - email exists } else { } $query = "INSERT INTO contacts VALUES ('','$name','$phone','$email')"; mysql_query($query);     //begin message     $message = <<<EOF <html>   <body bgcolor="#333333"> <table width="511" border="0" cellpadding="0" cellspacing="0">   <!--DWLayoutTable-->   <tr>     <td width="511" height="113" valign="top"><img src=[/code] What am i doing wrong!!!?? Chaz
  2. [quote author=chris9902 link=topic=109942.msg443592#msg443592 date=1159526134] it's been a long time since I've done any PHP coding so if it doesn't work... sorry. [code]$check = mysql_query("SELECT email FROM contacts"); $result = mysql_fetch_array($check); foreach ($result as $i) { if ($i == $_POST['requiredemail']) { exit("dupe"); } }[/code] what this *should* do is select all the "email" fields from "contacts" and store them in a new array. then the foreach() loops through them one by one and check them against $_POST['requiredemail']. it's a $i matches $_POST['requiredemail'] it will exit(). you can tidy this up a bit so it could print an error message or something. [/quote] Thanks. Where would the code go in my PHP then, just with all the other code? The database is currently empty - what I want to do is stop duplicates from appearing. Is this how to do it? Chaz
  3. Hi guys I have created the following PHP script which works perfectly - sends name, phone and email to a mySQL database. What I need to do it somewhere put in a command that checks the Database for duplicate email entries - The email sends out discount details for the shop so we only want to send one per email address. Is this possible? How would I go about doing this? Cheers Chas [code]$name=$_POST['requiredname']; $phone=$_POST['requiredphone']; $email=$_POST['requiredemail']; $from = "info@hairkandi.com"; $subject = "Hair Kandi Discount Voucher"; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query = "INSERT INTO contacts VALUES ('','$name','$phone','$email')"; mysql_query($query);     //begin message     $message = <<<EOF <html>   <body bgcolor="#333333">[/code]
  4. Hi guys, I am a complete PHP newbie - I am helping a mate design a form on his website for people to sign up for a newsletter, and when they do they get emailed a HTML 50% off voucher. I have the MySQL database, the form and the PHP working to submit the details to the SQL and that works perfectly. There are only 3 fields on the form - Name, phone and email. What I am now trying to do is send an HTML email to the email address they specify - so effectively it sends the voucher automatically. When the script is run it forwards them to a thankyou html page. I found the PHP for the HTML email on this site somewhere, and put it in my script. When I press submit on the form, it submits the data and displays the thanks page, and no email appears! The code is below - any ideas where I am going wrong? I have only been using PHP for 3 days now, and its great! I hope to get into it more! Chas [code]<? $database="web15-hairkandi"; $name=$_POST['name']; $phone=$_POST['phone']; $email=$_POST['email']; $from = "info@hairkandi.com"; $subject = "Hello! This is HTML email"; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query = "INSERT INTO contacts VALUES ('','$name','$phone','$email')"; mysql_query($query);     //begin message     $message = <<<EOF <html>   <body bgcolor="#DCEEFC">     <center>         <b>TEST EMAIL</b> <br>         <font color="red">DOES THIS WORK?</font> <br>         <a href="http://www.google.com/">* maaking.com</a>     </center>       <br><br>TEST TEST <br> TEST<br>TEST   </body> </html> EOF;   //end of message     $headers  = "From: $from\r\n";     $headers .= "Content-type: text/html\r\n";     $email = "$email, $from"; // this will send to both emails at the same time.     // now lets send the email.     mail($email, $subject, $message, $headers); header( "Location: thanks.htm" ); mysql_close(); ?>[/code]
×
×
  • 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.