Jump to content

On Form Submit - Check email for Duplicates


adriscoll

Recommended Posts

Hello 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.

 

$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:

<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):

<?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 = "[email protected]";
$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.";
  


?>

If you need to check for a particular event then you will need to add a WHERE clause to your query.  I'm not sure of your table column names so I'm totally guessing here but it will likely be like...

 

$sql_email_check = mysql_query("SELECT email FROM users WHERE email='$email' AND event_type='$event_name'");

  • 4 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.