PHP - Duplicate Check Of Email Before Form Submit
Hello,
I have looked on the forum, but haven't found the answer to this. I have a basic [name, email, phone, event] web form and want to make sure there person is not submitting twice by doing duplicate check of the mail. I looked at other solutions that suggested setting up unique IDs for each user, but it would be possible for a user to sign up for more then one event. Any info would be helpful. Not a newbie, but not an expert. Similar TutorialsHello all. I have seen a few threads that loosely deal with ways to do this, but haven't seen anything yet that speaks to this scenario. I have a page (volunteer_signup.php) that shows events to participate in and it passes some variables to a second page (volunteer.php)which is a form for individuals to enter their credentials and that appends to the event detail passed from the first page. I want to be able to check that their email isn't already associated with this particular event, but it is allowed to be in the database for another event. I wanted to do something like the code below, but don't know how to incorporate that with the form (or in volunteerDB.php) any help would be great. thank you in advance. Code: [Select] $sql_email_check = mysql_query("SELECT email FROM users WHERE email='$email'"); $email_check = mysql_num_rows($sql_email_check); if($email_check > 0) { echo "Email is already in our database. Please enter a different email !! <br />"; } exit(); } current form: Code: [Select] <html> <?php include('dbconfig.php'); $event_id = $_GET['id']; $park = $_GET['park']; $orderdate = $_GET['orderdate']; $description = $_GET['description']; $leader = $_GET['leader']; $hour = $_GET['hour']; $min = $_GET['min']; $ampm = $_GET['ampm']; echo $orderdate; echo "<BR>"; echo $park; echo "<BR>"; echo $description; echo "<BR>"; echo $hour; echo ":"; echo $min; echo $ampm; ?> <body> <form enctype="multipart/form-data" action="volunteerDB.php" method="POST" name="myform"> <table border="1"> <input type="hidden" name="event_id" value=<?php echo $event_id; ?>> <input type="hidden" name="park" value=<?php echo $park; ?>> <input type="hidden" name="orderdate" value=<?php echo $orderdate; ?>> <input type="hidden" name="description" value=<?php echo $description; ?>> <input type="hidden" name="leader" value=<?php echo $leader; ?>> <input type="hidden" name="hour" value=<?php echo $hour; ?>> <input type="hidden" name="min" value=<?php echo $min; ?>> <input type="hidden" name="ampm" value=<?php echo $ampm; ?>> <tr> <td>First Name</td> <td> <input name="firstname" /> </td> </tr> <tr> <td>Last Name</td> <td> <input name="lastname" /> </td> </tr> <tr> <td>Email</td> <td> <input name="email" /> </td> </tr> <tr> <td>Phone</td> <td> <input name="phone" /> </td> </tr> <tr> </tr> </table> <input type="submit" value="Submit" onclick="verify();"> </td> </tr> </form> </body> </html> form feeds to this php page (volunteerDB.php): Code: [Select] <?php include('dbconfig.php'); $event_id = $_POST['event_id']; $park = $_POST['park']; $orderdate = $_POST['orderdate']; $description = $_POST['description']; $leader = $_POST['leader']; $hour = $_POST['hour']; $min = $_POST['min']; $ampm = $_POST['ampm']; $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $email = $_POST['email']; $phone = $_POST['phone']; $email_list = $_POST['email_list']; // Make a MySQL Connection mysql_connect("localhost", "$user", "$password") or die(mysql_error()); mysql_select_db("$database") or die(mysql_error()); mysql_query("INSERT INTO volunteer (id, event_id, park, firstname, lastname, email, phone, email_list) VALUES('', '$event_id', '$park', '$firstname', '$lastname', '$email', '$phone', '$email_list') ") or die(mysql_error()); ?> <?php $to = "$email"; $subject = "Trailworker Event Signup Confirmation"; $message = "Hello $firstname! Thank you for signing up to work the $park trailworker event. A crew leader will contact you shortly. Park: $park Date: $orderdate Time: $hour:$min $ampm Description: $description Crew Leader: $leader"; $from = "info@xxxxxxxxxx.com"; $headers = "From: $from"; mail($to,$subject,$message,$headers); echo "Thank you for signing up. You will receive an email shortly letting you know event details and who your crew leader is."; ?> Hi there everyone, I have the below code (needs to be sanitized for SQL injection - i know ). Submitting to a MYSQL database. I wish to check on form submit if the users email address already exists, and if so display a simple error message (even just a windows error message) stating "the email address you have entered already exists". I don't really know where to start with this, or what the code should look like, so any help and direction would be massively appreciated. All i do know, is the email column is set to unique, and when i attempt to submit using an email i know exists the code appears to run successfully without spitting out any errors (i.e. the web url changes to the below php code) but the table doesn't update (which is correct). I just don't know how to then return the user to the form (preferably with all their info still entered) when this happens along with a nice error message... Kind regards, Tom. Code: [Select] <? $localhost="00.000.000.00"; $username="###"; $password="###"; $database="mfirst"; $firstname=$_POST['firstname']; $surname=$_POST['surname']; $dob="{$_POST['dobyear']}-{$_POST['dobmonth']}-{$_POST['dobday']}"; if (isset ($_POST['permissionnewsletter']) || (!empty ($_POST['permissionnewsletter']))) { $permissionnewsletter = "Yes"; } else { $permissionnewsletter = "No"; } $email=$_POST['email']; $userpassword=$_POST['userpassword']; $telephone=$_POST['telephone']; mysql_connect($localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $insertintocustomerdetail = "INSERT INTO customerdetail VALUES (NULL,'$firstname','$surname','$dob','$permissionnewsletter','$email','$userpassword','$telephone',now())"; mysql_query($insertintocustomerdetail); $addressline1=$_POST['addressline1']; $addressline2=$_POST['addressline2']; $cityortown=$_POST['cityortown']; $county=$_POST['county']; $postcode=$_POST['postcode']=strtoupper(@$_REQUEST['postcode']); $insertintoaddresstable = "INSERT INTO addresstable VALUES (NULL,LAST_INSERT_ID(),'$addressline1','$addressline2','$cityortown','$county','$postcode',now())"; mysql_query($insertintoaddresstable); mysql_close(); ?> Hi all, What I am trying to achieve is, I thought quite simple! Basically, a user signs up and chooses a package, form is submitted, details added to the database, email sent to customer, then I want to direct them to a paypal payment screen, this is where I am having issues! Is their any way in php to submit a form without user interaction? Here is my code for the form process page Code: [Select] <?php include('config.php'); require('scripts/class.phpmailer.php'); $package = $_POST['select1']; $name = $_POST['name']; $email = $_POST['email']; $password = md5($_POST['password']); $domain = $_POST['domain']; $a_username = $_POST['a_username']; $a_password = $_POST['a_password']; $query=mysql_query("INSERT INTO orders (package, name, email, password, domain, a_username, a_password) VALUES ('$package', '$name', '$email', '$password', '$domain', '$a_username', '$a_password')"); if (!$query) { echo "fail<br>"; echo mysql_error(); } else { $id = mysql_insert_id(); $query1=mysql_query("INSERT INTO customers (id, name, email, password) values ('$id', '$name', '$email', '$password')"); if (!$query1) { echo "fail<br>"; echo mysql_error(); } if($package=="Reseller Hosting") { //email stuff here - all works - just cutting it to keep the code short if(!$mail->Send()) { echo "Message could not be sent. <p>"; echo "Mailer Error: " . $mail->ErrorInfo; exit; } ?> <form name="_xclick" action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_xclick-subscriptions"> <input type="hidden" name="business" value="subscription@jollyhosting.com"> <input type="hidden" name="currency_code" value="USD"> <input type="hidden" name="item_name" value="Jolly Hosting Reseller Packages"> <input type="hidden" name="no_shipping" value="1"> <!--1st month --> <input type="hidden" name="currency_code" value="USD"> <input type="hidden" name="a3" value="3.00"> <input type="hidden" name="p3" value="1"> <input type="hidden" name="t3" value="M"> <input type="hidden" name="src" value="1"> <input type="hidden" name="sra" value="1"> </form>'; <?php } //last } //end ?> I have a form in the follwoing link: http://isupportentourage.dyndns.info//CARES/application.htm I would like to send the inputs to an email address so I have used a php file called sendEmail.php which has the following code: <?php $redirectTo = "http://www.yahoo.com"; $to = "fatemeh.elmi@gmail.com"; $subject = "Form Submission"; $headers = "From:\r\n"; $message = ""; $formFields = array_keys($_POST); for ($i = 0; $i < sizeof($formFields); $i++) { $theField = strip_tags($formFields[$i]); $theValue = strip_tags($_POST[$theField]); $message .= $theField; $message .= " = "; $message .= $theValue; $message .= "\n"; } $success = mail($to, $subject, $message, $headers); if ($success) { header("Location: " . $redirectTo); } else { echo "An error occurred when sending the email."; } ?> Could someone tell me why it is not working at all. <form action="form-to-email.php" method="post" enctype="text/plain" class="form"> <p class="name"> <i class="icon-user"></i> <input type="text" name="name" id="name" /> <label for="name">Name</label> </p> <p class="email"> <i class="icon-envelope"></i><span id="sprytextfield1"> <input type="text" name="email" id="email" /> </span> <label for="email">E-mail</label> </p> <p class="phone"><i class="icon-phone-sign"></i> <input type="text" name="phone" id="phone" /> <label for="web">Phone</label> </p> <p class="text"><span id="sprytextarea1"> <textarea name="text"></textarea> <span class="textareaRequiredMsg">A value is required.</span></span></p> <p class="submit"> <input type="submit" name="submit" id="submit" value="Send message"> </p> </form>The form is located in index.html and separate page is form-to-email.php. Do I need to link them <link href=>, <link rel=> or the files just need to be in the same folder? <?php if(!isset($_POST['submit'])) { //This page should not be accessed directly. Need to submit the form. echo "error; you need to submit the form!"; } $name = $_POST['name']; $visitor_email = $_POST['email']; $message = $_POST['message']; //Validate first if(empty($name)||empty($visitor_email)) { echo "Name and email are mandatory!"; exit; } if(IsInjected($visitor_email)) { echo "Bad email value!"; exit; } $email_from = '$visitor_email \r\n"'; $email_subject = "New Form submission"; $email_body = "You have received a new message from the user $name.\n". "Here is the message:\n $message". $to = "2d2f@gmail.com";//<== update the email address $headers = "From: $email_from \r\n"; $headers .= "Reply-To: $visitor_email \r\n"; //Send the email! mail($to,$email_subject,$email_body,$headers); //done. redirect to thank-you page. header('Location: thank-you.html'); I have made a form that asks a user for email, first name, last name, and password. I am using Spry validation tools in Dreamweaver. When I used those only, I did not have a problem. The problem began once I tried to actually check to see if the email was already registered. I have tried changing so many things like what $_POST variable to look for at the beginning, to different db connection arrangements. I am stumped. The only other thing I can think of is that I have the order wrong somehow in the logic. Thanks for the help. First, here is the form: Code: [Select] Enter Email<?php if($error_email_taken) echo ": $error_email_taken."; ?> <form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <input name="email" type="text" id="email" value="<?php if($_POST["email"]) echo $_POST["email"]; ?>"> <input name="first" type="text" id="first" value="<?php if($_POST["first"]) echo $_POST["first"]; ?>"> <input name="last" type="text" id="last" value="<?php if($_POST["last"]) echo $_POST["last"]; ?>"> <input name="pass" type="password" class="formText1" id="pass" value="<?php if($_POST["pass"]) echo $_POST["pass"]; ?>"> <input type="submit" name="Submit" value="Submit"></td> </form> And the email verification and insert, which is placed before the opening html tag. Code: [Select] <?php if($_POST['Submit']) { //Check to see if email is registered. $email = $_POST['email']; $dbc=mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $q_1 = "SELECT users_email FROM table WHERE users_email = $email"; $r_1 = mysqli_query($dbc, $q_1); $rows_1 = mysqli_num_rows($r_1); if ($rows_1 == 0) { //If 0, email is not already registered. $new_email = $_POST['email']; } else { $error_email_taken = "This email is already registered."; } //If everything is good, insert the information. if(isset($new_email)) { $first_name = $_POST['first']; $last_name = $_POST['last']; $password = $_POST['pass']; //Insert User information. $q_2 = "INSERT INTO table (users_email, users_first, users_last, users_pass) VALUES ('$new_email', '$first_name', '$last_name', '$password')"; $r_2 = mysqli_query($dbc, $q_2); //Go to new page if form was submitted and information properly inserted. header('Location: new_page.php'); }//End: if($new_email) } //End: if $_POST['submit'] ?> I've simplified it as much as I could. I totally eliminated stuff like a password hash, etc. because I wanted to get it down to the most simple form, so once this gets working, I'll add that other stuff later. Thanks so much again. Hi, I am new to php and I desperately need help inserting an image into my php submit form. The form works perfectly but I have no idea how to get an image to be shown when the recipeint fo the email receive it (would love to have my company logo at the top of the mail just after $message.. Below is my code : .... // Create Mail Message and Send Mail $to = 'x@domain.coma'; $subject = "Website Enquiry Received from www.domain.com"; $message = "The following message has been sent from the website." . "\n" . "\n" . "Date Sent: " . date("j F Y") . "\n" . "Date Sent: " . date("g:i a") . "\n" . "\n" . "From: $contactName $contactSurname" . "\n" . "\n" . "Their Contact & Personal Details" . "\n" . "=====================" . "\n" . "\n" . "Marital Status: $contactStatus" . "\n" . "Email: $contactEmail" . "\n" . "Cellphone Number: $contactNumber" . "\n" . "Address 1: $contactAddress1" . "\n" . "Address 2: $contactAddress2" . "\n" . "Suburb: $contactSuburb" . "\n" . "Postal Code: $contactPostalcode" . "\n" . "\n" . "\n" . $headers = "From: $contactName $contactSurname <$contactEmail>" . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); mail($contactEmail, 'Confirmation of email: "' . $subject . '"', $message, $headers); // Thank You Message header('Refresh: 0; url=/quote_confirm.htm'); } } ?> i wanting users to be able to update there email address and check to see if the new email already exists. if the email is the same as current email ignore the check. i have no errors showing up but if I enter a email already in the db it still accepts the new email instead of bringing the back the error message. Code: [Select] // email enterd from form // $email=$_POST['email']; $queryuser=mysql_query("SELECT * FROM members WHERE inv='$ivn' ") or die (mysql_error()); while($info = mysql_fetch_array( $queryuser )) { $check=$info['email']; // gets current email // } if($check!=$email){ // if check not equal to $email check the new email address already exists// $queryuser=mysql_query("SELECT * FROM members WHERE email='$email' "); //$result=mysql_query($sql); $checkuser=mysql_num_rows($queryuser); if($checkuser != 0) { $error= "0"; header('LOCATION:../pages/myprofile.php?id='.$error.''); } } cheers Hola Everybody !! I'm putting together a web app similar to Digg and was wondering if there is a function or code example I can use to avoid users submitt the same url. For example: Right now the user can submit; 1. http://www.example.com?post01 2. http://example.com?post01 3. www.example.com?post01 I want the web app to check if the link has been submitted by the user first and look for duplicate submission. Any ideas ? Thank you, V. Hello, i've got this code, to insert some form data into my db, it checks for a value if it exists already, it won't insert, now i want to add another value to check, but i don't know how. This is my code: Code: [Select] <?php if(isset($_POST['submit'])){ if (strlen($_POST['code']) == 12 && substr($_POST['code'],0,6) == '610147'){ $code = $_POST['code']; $select_query = mysql_query("SELECT * FROM jupiter WHERE code = '$code'"); if(mysql_num_rows($select_query) == 0){ $remote_addr = $_SERVER['REMOTE_ADDR']; $secret = $_POST['euro']; mysql_query("INSERT INTO jupiter(code,euro,ip,date,used) VALUES('$code','$secret','$remote_addr',CURDATE(),'n')"); } Print "<font color='green'>OK</font>"; } else { Print "<font color='red'>Error</font>"; } }?> This checks if "code" already exists, now i want to also have it check for "ip" Can someone help me out here please. Thanks ! Hello, i am inserting some form data into my mysql db, i happen to get some duplicates so i want to check first if the entry exists already before i insert. my current code: Code: [Select] <?php if(isset($_POST['submit'])) { ?> <?php if (strlen($_POST['code']) == 19 && substr($_POST['code'],0,7) == '5541258') { mysql_query("INSERT INTO table(code,secret,ip,date) VALUES('$_POST[code]','$_POST[secret]','$_SERVER[REMOTE_ADDR]',CURDATE())"); Print "<font color='green'>The code will be checked now</font>"; } else { Print "<font color='red'>The code is invalid</font>"; } ?><?php } ?> I would like to use the value 'code' to check if the entry exists, that one is unique for each entry. How would i do that ? Thanks ! Hi, I need help to check multiple rows for many columns, so that the script won't re-insert a duplicate entry. For eg: $isRowExist=mysql_query("SELECT (field1,field2) from table1 WHERE field1='$f1' AND field2='$f2' "); if(mysql_num_rows($isRowExist)==1) print "already in table1!"; else //proceed to insert into table table1 *BUT I tried this and it says mysql_num_rows expects resource, and this warning only shows when I have multipel columns I want to compare (it works just fine with one column in the WHERE clause above) Please help! I'm working on a directory component and have kind of a tricky thing I need to do. The list of results pop through ajax on the left side along with it's google map number tag, and the google map pops on the right side. To make it even trickier the results are popped through a radius search by proximity. The problem is if there are multiple results with the same address you end up having all of the number tags on the map buried under the last tag with that address, plus it makes for kind of a long list. What I need to do is run a check to see if the previous result is the same address, and if yes not pop that result in a new table cell, rather stick it in a jquery drop down div so that all of the following results with the same address are stuffed in the jquery drop down in the same table cell under the first result with that address. In a perfect world all of the listings with the same addresses would be submitted in order so I could just do a check for the previous itemid's address, but of course that's not the case. I thought about running a query to grab ALL of the addresses and then check the item's address against it to see if it matches and if yes echo the jquery div instead of the <td>, but obviously that won't work because that will cause the first item with that address to be put in the div also. Plus I don't know if that's a very efficient way to go about it anyway. Here's kind of the basic thing I'm working with: Code: [Select] $query = "SELECT data_txt FROM jos_sobi2_fields_data WHERE fieldid = 76 AND itemid = $mySobi->id"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ $myaddress = $row['data_txt']; } echo "<td $style>"; Any ideas? I've created a script to remove duplicate emails and it works perfectly up to about 20k. After that it just stops with no error code. I'm baffled. I've increased the max_execution_time to 2 hours even though this script just takes a few minutes. <?PHP function validElement($element) { return strlen($element) > 1; } function in_iarray($str, $a){ foreach($a as $v){ if(strcasecmp($str, $v)==0){return true;} } return false; } remove_duplicates(); } //Remove more duplicates from list function array_iunique($a){ $n = array(); foreach($a as $k=>$v){ if(!in_iarray($v, $n)){ echo $v; $n[$k]=$v;} } return $n; } //Remove duplicates from list function remove_duplicates() { $p = 0; while ($p != 1) { $rawemaillist = array_values(array_filter($rawemaillist, "validElement")); $p = 1; } $initial = count($rawemaillist); $k = 0; while ($k != 1) { $rawemaillist = array_iunique($rawemaillist); $k = 1; } ?> The script works fine - but only up to around 20 k - which leads me to believe its a server setting issue. Is there something in the php.ini file I should or otherwise a setting that I should be looking at to change??? I am working on a web form in PHP which accepts a Paypal Email address from the user. I need to authenticate (validate or check) if the Paypal email address entered is a valid Paypal email account. Please reply. All comments and feedback are welcomed. Thank you! I need Delete Duplicate Email Records That Are Attached To One Account But Can Be Found In Multiple Accounts I have a table, consumer_mgmt. It collects consumer information from various forms. These forms are available through different pages that are part of a business package. A business can offer these signups to gather names and emails from consumers for various types of specials they may offer. So a consumer my be in the consumer_mgmt table 5, 10, 15 times for that particular business. But, that consumer may be in the consumer_mgmt table multiple times for a different business. So multiple times for multiple businesses. I need to remove duplicates for each business account so the consumer is only the consumer_mgmt only once for each business. There are approximately 15,000 rows currently in the consumer_mgmt table. I'm not sure where to begin on the logic. Since there are multiple business accounts that the emails are attached to, would one have to build a case for each loop? Say I have an "Entries" table. I want to submit same multiple entries using a form submission. And If I have other queries submitted in the same form, I want those quarries to be submitted only once. Is that possible to do? Here's my code. if(isset($_POST['submit'])) { $entries = 10; $id = 55; $name = 'Smith'; $insert = $db->prepare("INSERT INTO entries(id, name) VALUES(:id, :name)"); $insert->bindParam(':id', $id); $insert->bindParam(':name', $name); $result_insert = $insert->execute(); if($result_insert == false) { echo 'Fail'; } else { echo 'Success'; } } ?> <form action="" method="post"> <input type="submit" name="submit" value="SUBMIT" /> </form> Edited January 13, 2019 by imgrooot Hello All, I am new to PHP and I am trying to modify a already written script since I want to add a checkbox to my site. In the front end I have Code: [Select] <input type="checkbox" name="privateurlcheck" id="privateurlcheck" value="0"> in the php I have var privateurlcheck = document.getElementById( "privateurlcheck" ).value Then in the mysql data insert php page, $records[channel_protected] = $postData[privateurlcheck] ; In MySQL "channel_protected" field is "ENUM" with Values '0','1' When I run the code I see 0 in the MySQL channel_protected field even when I check the checkbox. All other values that are passed on to mysql such as name, age are posted correctly without any issues. Can you please let me know how can I get 0 or 1 in the mysql depening on the checkbox status? It is 5AM and I am trying to figure this for 2nd consecutive day! Greatly appreciate if any one can help me out. Hello. I have a form where people can sign up for events. I want to stop them from signing up for the same event multiple times, and wanted to know if it is possible to do some type of check before insert. I need help with the theory of how this would be accomplished. |