Jump to content

[SOLVED] PHP Email form to add fields to my database


craigtolputt

Recommended Posts

Hi Guys,

 

Im not sure if this is possible and when i tried adding the code that i thought it was the form just dissapears...

 

So i have this php email form:


<div id="contact2">

<?php
	// Attention! Please read the following.
	// It is important you do not edit pieces of code that aren't tagged as a configurable options identified by the following:

        // Configuration option.

	// Each option that is easily editable has a modified example given.


	$error    = '';
        $name    = ''; 
        $address    = '';
        $address2  = ''; 
        $town = ''; 
        $postcode   = '';
	$phone   = '';
	$email = '';
	$interest = '';

        if(isset($_POST['signup'])) {
        
        $name    = $_POST['name'];
        $address   = $_POST['address'];
        $address2  = $_POST['address2'];
        $town = $_POST['town'];
        $postcode   = $_POST['postcode'];
	$phone   = $_POST['phone'];
	$email   = $_POST['email'];
	$interest   = $_POST['interest'];


        if(trim($name) == 'Your Name') {
        	$error = '<div class="error_message">Attention! Please enter your name.</div>';
       
       } else if(trim($address) == 'Address') {
        	$error = '<div class="error_message">Attention! Please enter your address.</div>';
        } else if(trim($postcode) == 'Postcode') {
        	$error = '<div class="error_message">Attention! Please enter your postcode.</div>';
        } else if(!is_numeric($phone)) {
          $error = '<div class="error_message">Attention! Phone number can only contain digits.</div>';
       
        } else if(trim($email) == 'Email address') {
        	$error = '<div class="error_message">Attention! Please enter a valid e-mail address.</div>';
        } else if(!isEmail($email)) {
        	$error = '<div class="error_message">Attention! You have enter an invalid e-mail address, try again.</div>';
        }

        if(trim($interest) == 'Please select') {
        	$error = '<div class="error_message">Attention! Please select area of interest.</div>';
        }

        if($error == '') {
        
		if(get_magic_quotes_gpc()) {
            	$comments = stripslashes($comments);
            }


         // Configuration option.
	 // Enter the email address that you want to emails to be sent to.
	 // Example $address = "joe.doe@yourdomain.com";

         //$address = "craig@tolputtkeeton.co.uk";
	 $address = "info@branston-golf-club.co.uk";


         // Configuration option.
         // i.e. The standard subject will appear as, "You've been contacted by John Doe."

         // Example, $e_subject = '$name . ' has contacted you via Your Website.';

         $e_subject = 'You have a Promotions sign up interested in:  ' . $interest . '.';


         // Configuration option.
	 // You can change this if you feel that you need to.
	 // Developers, you may wish to add more fields to the form, in which case you must be sure to add them here.

	 $e_body = "$name has signed up for promotions and is interested in $interest.\r\n\n";
	 $e_content = "Their details are:\r\n\n";
	 $e_details = "$name\n$address\n$address2\n$town\n$postcode\n\n$phone\n\n$email\r\n\n";

	 // Configuration option.
       	 // RIf you active phone number, swap the tags of $e-reply below to include phone number.
	 //$e_reply = "You can contact $name via email, $email or via phone $phone";
	 $e_reply = "You can contact them via email, $email";

         $msg = $e_body . $e_content . $e_details . $e_reply;

         mail($address, $e_subject, $msg, "From: $email\r\nReply-To: $email\r\nReturn-Path: $email\r\n");


	 // Email has sent successfully, echo a success page.

	 echo "<div id='succsess_page'>";
	 echo "<h1>Email Sent Successfully.</h1>";
	 echo "<p>Thank you <strong>$name</strong>, your message has been submitted to us.</p>";
	 echo "</div>";
                      
	}
}

         if(!isset($_POST['signup']) || $error != '') // Do not edit.
         {
?>

            <?php echo $error; ?>
            
            <form  method="post" action="">

            <input name="name" type="text" value="Your Name" onfocus="if (this.value == this.defaultValue) {this.value='';}" onblur="if (this.value == '') {this.value = this.defaultValue;}" class="email"/>

		<br />
            <input name="address" type="text" value="Address" onfocus="if (this.value == this.defaultValue) {this.value='';}" onblur="if (this.value == '') {this.value = this.defaultValue;}" class="tel"/>

		<br />
            <input name="address2" type="text" value="Address Cont" onfocus="if (this.value == this.defaultValue) {this.value='';}" onblur="if (this.value == '') {this.value = this.defaultValue;}" class="tel"/>

		<br />
            <input name="town" type="text" value="Town" onfocus="if (this.value == this.defaultValue) {this.value='';}" onblur="if (this.value == '') {this.value = this.defaultValue;}" class="tel"/>

		<br />
            <input name="postcode" type="text" value="Postcode" onfocus="if (this.value == this.defaultValue) {this.value='';}" onblur="if (this.value == '') {this.value = this.defaultValue;}" class="tel"/>

		<br />
            <input name="phone" type="text" value="Tel number" onfocus="if (this.value == this.defaultValue) {this.value='';}" onblur="if (this.value == '') {this.value = this.defaultValue;}" class="tel"/>

		<br />
            <input name="email" type="text" value="Email address" onfocus="if (this.value == this.defaultValue) {this.value='';}" onblur="if (this.value == '') {this.value = this.defaultValue;}" class="tel"/>

            <br />
            <label>Please select area of interest</label>
            <select name="interest" class="interest">
              <option value="">Please select</option>
              <option value="The Club">The Club</option>
              <option value="Health & Fitness">Health & Fitness</option>
              <option value="Golf">Golf</option>
              <option value="Events">Events</option>
              <option value="Business">Business</option>
              <option value="Weddings">Weddings</option>
            </select>
            
            <br />
            
            <input name="signup" type="submit" class="submit" value="send" />

            </form>

<?php } 

?>            
</div>

 

And i need to add some code to it so that not only does it send an email like it already does but it also adds the data to my database...

 

so i tried changing the form so that it was this:


<div id="contact2">
<?php
//include the connect script
include "connect.php";

/*THIS VARIABLE IS WHAT TABLE YOU ARE USING...IF YOU USED MY SQL FILE, THEN YOUR DEFAULT TABLE*/
/*NAME SHOULD BE 'userv2' AND YOU DO NOT NEED TO CHANGE ANYTHING, BUT IF YOU MADE YOUR OWN TABLE,*/
/*CHANGE THIS VARIABLE.*/
	$tableName = "dataget";
	$error    = '';
        $first_name    = '';
	$last_name    = ''; 
        $address    = '';
        $address2  = ''; 
        $town = ''; 
        $postcode   = '';
	$phone   = '';
	$email = '';
	$interest = '';

        if(isset($_POST['signup'])) {
	//Post all of the users information (md5 Encrypt the dna_no)
	$first_name    = $_POST['first_name'];
	$last_name    = $_POST['last_name'];
        $address   = $_POST['address'];
        $address2  = $_POST['address2'];
        $town = $_POST['town'];
        $postcode   = $_POST['postcode'];
	$phone   = $_POST['phone'];
	$email   = $_POST['email'];
	$interest   = $_POST['interest'];

	if(trim($first_name) == 'First Name') {
        	$error = '<div class="error_message">Attention! Please enter your First Name.</div>';
       } else if(trim($last_name) == 'Last Name') {
        	$error = '<div class="error_message">Attention! Please enter your Last Name.</div>';
        } else if(trim($address) == 'Address') {
        	$error = '<div class="error_message">Attention! Please enter your address.</div>';
        } else if(trim($postcode) == 'Postcode') {
        	$error = '<div class="error_message">Attention! Please enter your postcode.</div>';
        } else if(!is_numeric($phone)) {
          $error = '<div class="error_message">Attention! Phone number can only contain digits.</div>';
       
        } else if(trim($email) == 'Email address') {
        	$error = '<div class="error_message">Attention! Please enter a valid e-mail address.</div>';
        } else if(!isEmail($email)) {
        	$error = '<div class="error_message">Attention! You have enter an invalid e-mail address, try again.</div>';
        }

        if(trim($interest) == 'Please select') {
        	$error = '<div class="error_message">Attention! Please select area of interest.</div>';
        }

        if($error == '') {
        
	if(get_magic_quotes_gpc()) {
            	$comments = stripslashes($comments);
            }

$insert = mysql_query("INSERT INTO $tableName (first_name,last_name,address,address2,town,postcode,phone,email,interest) VALUES ('$first_name','$last_name''$address','$address2','$town','$postcode','$phone','$email','$interest')") or die(mysql_error());

// Configuration option.
	 // Enter the email address that you want to emails to be sent to.
	 // Example $address = "joe.doe@yourdomain.com";

         $address = "craig@tolputtkeeton.co.uk";
	 //$address = "info@branston-golf-club.co.uk";


         // Configuration option.
         // i.e. The standard subject will appear as, "You've been contacted by John Doe."

         // Example, $e_subject = '$name . ' has contacted you via Your Website.';

         $e_subject = 'You have a Promotions sign up interested in:  ' . $interest . '.';


         // Configuration option.
	 // You can change this if you feel that you need to.
	 // Developers, you may wish to add more fields to the form, in which case you must be sure to add them here.

	 $e_body = "$name has signed up for promotions and is interested in $interest.\r\n\n";
	 $e_content = "Their details are:\r\n\n";
	 $e_details = "$name\n$address\n$address2\n$town\n$postcode\n\n$phone\n\n$email\r\n\n";

	 // Configuration option.
       	 // RIf you active phone number, swap the tags of $e-reply below to include phone number.
	 //$e_reply = "You can contact $name via email, $email or via phone $phone";
	 $e_reply = "You can contact them via email, $email";

         $msg = $e_body . $e_content . $e_details . $e_reply;

         mail($address, $e_subject, $msg, "From: $email\r\nReply-To: $email\r\nReturn-Path: $email\r\n");


	 // Email has sent successfully, echo a success page.

	 echo "<div id='succsess_page'>";
	 echo "<h1>Email Sent Successfully.</h1>";
	 echo "<p>Thank you <strong>$name</strong>, your message has been submitted to us.</p>";
	 echo "</div>";
                      
	}
}

         if(!isset($_POST['signup']) || $error != '') // Do not edit.
         {
?>

            <?php echo $error; ?>
            
            <form  method="post" action="">

            <input name="name" type="text" value="Your Name" onfocus="if (this.value == this.defaultValue) {this.value='';}" onblur="if (this.value == '') {this.value = this.defaultValue;}" class="email"/>

		<br />
            <input name="address" type="text" value="Address" onfocus="if (this.value == this.defaultValue) {this.value='';}" onblur="if (this.value == '') {this.value = this.defaultValue;}" class="tel"/>

		<br />
            <input name="address2" type="text" value="Address Cont" onfocus="if (this.value == this.defaultValue) {this.value='';}" onblur="if (this.value == '') {this.value = this.defaultValue;}" class="tel"/>

		<br />
            <input name="town" type="text" value="Town" onfocus="if (this.value == this.defaultValue) {this.value='';}" onblur="if (this.value == '') {this.value = this.defaultValue;}" class="tel"/>

		<br />
            <input name="postcode" type="text" value="Postcode" onfocus="if (this.value == this.defaultValue) {this.value='';}" onblur="if (this.value == '') {this.value = this.defaultValue;}" class="tel"/>

		<br />
            <input name="phone" type="text" value="Tel number" onfocus="if (this.value == this.defaultValue) {this.value='';}" onblur="if (this.value == '') {this.value = this.defaultValue;}" class="tel"/>

		<br />
            <input name="email" type="text" value="Email address" onfocus="if (this.value == this.defaultValue) {this.value='';}" onblur="if (this.value == '') {this.value = this.defaultValue;}" class="tel"/>

            <br />
            <label>Please select area of interest</label>
            <select name="interest" class="interest">
              <option value="">Please select</option>
              <option value="The Club">The Club</option>
              <option value="Health & Fitness">Health & Fitness</option>
              <option value="Golf">Golf</option>
              <option value="Events">Events</option>
              <option value="Business">Business</option>
              <option value="Weddings">Weddings</option>
            </select>
            
            <br />
            
            <input name="signup" type="submit" class="submit" value="send" />

            </form>

<?php } 

?>            
</div>

 

 

This only makes the form break.  Does anyone know how i can do this??

 

Also as an extra bonus is it possible to add all the data to one table and the also add only first_name. last_name and email to another table aswell???

 

 

thanks in advance

 

Craig

Link to comment
Share on other sites

Hi craigtolput,

 

You're missing a comma in your MySQL Query, change the below:

 

'$last_name''$address'

 

to:

 

'$last_name','$address'

 

Also, it's easy to add the same data to another table, just perform another query, i.e.:

 

$insert2 = mysql_query("INSERT INTO $tableName2 (first_name,last_name,email) VALUES ('$first_name','$last_name','$email')") or die(mysql_error());

 

Hope this helps.

Link to comment
Share on other sites

Thanks for spotting that,

 

I have now changed the form to this...

 


<div id="contact2">
<?php
//include the connect script
include "connect.php";

/*THIS VARIABLE IS WHAT TABLE YOU ARE USING...IF YOU USED MY SQL FILE, THEN YOUR DEFAULT TABLE*/
/*NAME SHOULD BE 'userv2' AND YOU DO NOT NEED TO CHANGE ANYTHING, BUT IF YOU MADE YOUR OWN TABLE,*/
/*CHANGE THIS VARIABLE.*/
	$tableName = "dataget";
	$tableName2 = "member";
	$error    = '';
        $first_name    = '';
	$last_name    = ''; 
        $address    = '';
        $address2  = ''; 
        $town = ''; 
        $postcode   = '';
	$phone   = '';
	$email = '';
	$interest = '';

        if(isset($_POST['signup'])) {
	//Post all of the users information (md5 Encrypt the dna_no)
	$first_name    = $_POST['first_name'];
	$last_name    = $_POST['last_name'];
        $address   = $_POST['address'];
        $address2  = $_POST['address2'];
        $town = $_POST['town'];
        $postcode   = $_POST['postcode'];
	$phone   = $_POST['phone'];
	$email   = $_POST['email'];
	$interest   = $_POST['interest'];

	if(trim($first_name) == 'First Name') {
        	$error = '<div class="error_message">Attention! Please enter your First Name.</div>';
       } else if(trim($last_name) == 'Last Name') {
        	$error = '<div class="error_message">Attention! Please enter your Last Name.</div>';
        } else if(trim($address) == 'Address') {
        	$error = '<div class="error_message">Attention! Please enter your address.</div>';
        } else if(trim($postcode) == 'Postcode') {
        	$error = '<div class="error_message">Attention! Please enter your postcode.</div>';
        } else if(!is_numeric($phone)) {
          $error = '<div class="error_message">Attention! Phone number can only contain digits.</div>';
       
        } else if(trim($email) == 'Email address') {
        	$error = '<div class="error_message">Attention! Please enter a valid e-mail address.</div>';
        } else if(!isEmail($email)) {
        	$error = '<div class="error_message">Attention! You have enter an invalid e-mail address, try again.</div>';
        }

        if(trim($interest) == 'Please select') {
        	$error = '<div class="error_message">Attention! Please select area of interest.</div>';
        }

        if($error == '') {
        
	if(get_magic_quotes_gpc()) {
            	$comments = stripslashes($comments);
            }

	$insert = mysql_query("INSERT INTO $tableName (first_name,last_name,address,address2,town,postcode,phone,email,interest) VALUES ('$first_name','$last_name','$address','$address2','$town','$postcode','$phone','$email','$interest')") or die(mysql_error());

	$insert2 = mysql_query("INSERT INTO $tableName2 (first_name,last_name,email) VALUES ('$first_name','$last_name','$email')") or die(mysql_error());

// Configuration option.
	 // Enter the email address that you want to emails to be sent to.
	 // Example $address = "joe.doe@yourdomain.com";

         $address = "craig@tolputtkeeton.co.uk";
	 //$address = "info@branston-golf-club.co.uk";


         // Configuration option.
         // i.e. The standard subject will appear as, "You've been contacted by John Doe."

         // Example, $e_subject = '$name . ' has contacted you via Your Website.';

         $e_subject = 'You have a Promotions sign up interested in:  ' . $interest . '.';


         // Configuration option.
	 // You can change this if you feel that you need to.
	 // Developers, you may wish to add more fields to the form, in which case you must be sure to add them here.

	 $e_body = "$fist_name $last_name has signed up for promotions and is interested in $interest.\r\n\n";
	 $e_content = "Their details are:\r\n\n";
	 $e_details = "$first_name $last_name\n$address\n$address2\n$town\n$postcode\n\n$phone\n\n$email\r\n\n";

	 // Configuration option.
       	 // RIf you active phone number, swap the tags of $e-reply below to include phone number.
	 //$e_reply = "You can contact $name via email, $email or via phone $phone";
	 $e_reply = "You can contact them via email, $email";

         $msg = $e_body . $e_content . $e_details . $e_reply;

         mail($address, $e_subject, $msg, "From: $email\r\nReply-To: $email\r\nReturn-Path: $email\r\n");


	 // Email has sent successfully, echo a success page.

	 echo "<div id='succsess_page'>";
	 echo "<h1>Email Sent Successfully.</h1>";
	 echo "<p>Thank you <strong>$name</strong>, your message has been submitted to us.</p>";
	 echo "</div>";
                      
	}
}

         if(!isset($_POST['signup']) || $error != '') // Do not edit.
         {
?>

            <?php echo $error; ?>
            
            <form  method="post" action="">

            <input name="first_name" type="text" value="First Name" onfocus="if (this.value == this.defaultValue) {this.value='';}" onblur="if (this.value == '') {this.value = this.defaultValue;}" class="email"/>

		<br />
            <input name="last_name" type="text" value="Last Name" onfocus="if (this.value == this.defaultValue) {this.value='';}" onblur="if (this.value == '') {this.value = this.defaultValue;}" class="email"/>

		<br />
            <input name="address" type="text" value="Address" onfocus="if (this.value == this.defaultValue) {this.value='';}" onblur="if (this.value == '') {this.value = this.defaultValue;}" class="tel"/>

		<br />
            <input name="address2" type="text" value="Address Cont" onfocus="if (this.value == this.defaultValue) {this.value='';}" onblur="if (this.value == '') {this.value = this.defaultValue;}" class="tel"/>

		<br />
            <input name="town" type="text" value="Town" onfocus="if (this.value == this.defaultValue) {this.value='';}" onblur="if (this.value == '') {this.value = this.defaultValue;}" class="tel"/>

		<br />
            <input name="postcode" type="text" value="Postcode" onfocus="if (this.value == this.defaultValue) {this.value='';}" onblur="if (this.value == '') {this.value = this.defaultValue;}" class="tel"/>

		<br />
            <input name="phone" type="text" value="Tel number" onfocus="if (this.value == this.defaultValue) {this.value='';}" onblur="if (this.value == '') {this.value = this.defaultValue;}" class="tel"/>

		<br />
            <input name="email" type="text" value="Email address" onfocus="if (this.value == this.defaultValue) {this.value='';}" onblur="if (this.value == '') {this.value = this.defaultValue;}" class="tel"/>

            <br />
            <label>Please select area of interest</label>
            <select name="interest" class="interest">
              <option value="">Please select</option>
              <option value="The Club">The Club</option>
              <option value="Health & Fitness">Health & Fitness</option>
              <option value="Golf">Golf</option>
              <option value="Events">Events</option>
              <option value="Business">Business</option>
              <option value="Weddings">Weddings</option>
            </select>
            
            <br />
            
            <input name="signup" type="submit" class="submit" value="send" />

            </form>

<?php } 

?>            
</div>

 

But it doesn't work?

Link to comment
Share on other sites

Hi craigtolput,

 

Replace your MySQL statements with the below:

 

$insert = mysql_query("INSERT INTO ".$tableName." (first_name,last_name,address,address2,town,postcode,phone,email,interest) VALUES ('".$first_name."','".$last_name."','".$address."','".$address2."','".$town."','".$postcode."','".$phone."','".$email."','".$interest."')") or die(mysql_error());

	$insert2 = mysql_query("INSERT INTO ".$tableName2." (first_name,last_name,email) VALUES ('".$first_name."','".$last_name."','".$email."')") or die(mysql_error());

 

I've just escaped all of the variables.

Link to comment
Share on other sites

Hi craigtolputt,

 

I've just been through all of the code and have noticed that you've got no MySQL connect code, so the query is unable to connect to your database.

 

Add some connect code either directly to the file or in a config file and include it, something like:

 

$dbname = "dbname";
$dbuser = "dbuser";
$dbpass = "dbpass";
$dbhost = "dbhost";

$sql_connect = mysql_connect($dbhost, $dbuser, $dbpass);
$sql_selectdb = mysql_select_db($dbname);

if (!$sql_connect || !$sql_selectdb)
{
die("Failed to connect to database");
}

 

Hope this helps.

Link to comment
Share on other sites

i have this in the form page

include "connect.php";

 

and this in connect.php

<?php
//YOU MUST FILL THESE OUT IN ORDER TO CONNECT TO THE DATABASE.
$host = "localhost";
$usernameDB = "my db";
$passwordDB = "my password";
$whichDB = "my db";
//connect with host,username and password
$con = mysql_connect($host,$usernameDB,$passwordDB);
//if it cant connect echo cant connect and mysql_error;
if (!$con) {
echo "unable to connect to DB";
echo mysql_error($con);
exit();
}
//select the database
$db = mysql_select_db($whichDB);
//if it cant open the DB, echo cant open DB and echo mysql_error
if (!$db) {
echo "unable to open DB";
echo mysql_error($db);
exit();
}
?>

 

 

Link to comment
Share on other sites

Hi,

 

I just tried adding this to check if the users has already signed up

//grab all the usernames in the table
	$sql1 = mysql_query("SELECT * FROM $tableName WHERE Identifier = '$email'");
	//get number of results from both queries
	$row1 = mysql_num_rows($sql1);

	if($row1 > 0) {
	$error = '<div class="error_message">Attention! Your e-mail is already added.</div>';
	}

 

But the form sends anyway and adds a duplicate

 

 

any ideas???

 

Link to comment
Share on other sites

//grab all the usernames in the table
	$sql1 = mysql_query("SELECT * FROM $tableName WHERE Identifier = '$email'");
	//get number of results from both queries
	$row1 = mysql_num_rows($sql1);

	if($row1 > 0) {
	$error = '<div class="error_message">Attention! Your e-mail is already added.</div>';
	}

 

I assume Identifier is actually referred to as email in your query?

Link to comment
Share on other sites

No that didnt seem to work :(

 

this is my page:

 

<div id="contact2">
<?php
//include the connect script
include "connect.php";

/*THIS VARIABLE IS WHAT TABLE YOU ARE USING...IF YOU USED MY SQL FILE, THEN YOUR DEFAULT TABLE*/
/*NAME SHOULD BE 'userv2' AND YOU DO NOT NEED TO CHANGE ANYTHING, BUT IF YOU MADE YOUR OWN TABLE,*/
/*CHANGE THIS VARIABLE.*/
	$tableName = "dataget";
	$error    = '';
        $first_name    = '';
	$last_name    = ''; 
        $address    = '';
        $address2  = ''; 
        $town = ''; 
        $postcode   = '';
	$phone   = '';
	$email = '';
	$interest = '';

	//grab all the usernames in the table
	$sql1 = mysql_query("SELECT * FROM $tableName WHERE email = '$email'");
	//get number of results from both queries
	$row1 = mysql_num_rows($sql1);

        if(isset($_POST['signup'])) {
	//Post all of the users information (md5 Encrypt the dna_no)
	$first_name    = $_POST['first_name'];
	$last_name    = $_POST['last_name'];
        $address   = $_POST['address'];
        $address2  = $_POST['address2'];
        $town = $_POST['town'];
        $postcode   = $_POST['postcode'];
	$phone   = $_POST['phone'];
	$email   = $_POST['email'];
	$interest   = $_POST['interest'];

	if(trim($first_name) == 'First Name') {
        	$error = '<div class="error_message">Attention! Please enter your First Name.</div>';
       } else if(trim($last_name) == 'Last Name') {
        	$error = '<div class="error_message">Attention! Please enter your Last Name.</div>';
        } else if(trim($address) == 'Address') {
        	$error = '<div class="error_message">Attention! Please enter your address.</div>';
        } else if(trim($postcode) == 'Postcode') {
        	$error = '<div class="error_message">Attention! Please enter your postcode.</div>';
        } else if(!is_numeric($phone)) {
          $error = '<div class="error_message">Attention! Phone number can only contain digits.</div>';
       
        } else if(trim($email) == 'Email address') {
        	$error = '<div class="error_message">Attention! Please enter a valid e-mail address.</div>';
        } else if(!isEmail($email)) {
        	$error = '<div class="error_message">Attention! You have enter an invalid e-mail address, try again.</div>';
        } else if($row1 > 0) {
		$error = '<div class="error_message">Attention! Your e-mail is already added.</div>';
	}

        if(trim($interest) == 'Please select') {
        	$error = '<div class="error_message">Attention! Please select area of interest.</div>';
        }

        if($error == '') {
        
	if(get_magic_quotes_gpc()) {
            	$comments = stripslashes($comments);
            }

	$insert = mysql_query("INSERT INTO ".$tableName." (first_name,last_name,address,address2,town,postcode,phone,email,interest) VALUES ('".$first_name."','".$last_name."','".$address."','".$address2."','".$town."','".$postcode."','".$phone."','".$email."','".$interest."')") or die(mysql_error());

// Configuration option.
	 // Enter the email address that you want to emails to be sent to.
	 // Example $address = "joe.doe@yourdomain.com";

         $address = "craig@tolputtkeeton.co.uk";
	 //$address = "info@branston-golf-club.co.uk";


         // Configuration option.
         // i.e. The standard subject will appear as, "You've been contacted by John Doe."

         // Example, $e_subject = '$name . ' has contacted you via Your Website.';

         $e_subject = 'You have a Promotions sign up interested in:  ' . $interest . '.';


         // Configuration option.
	 // You can change this if you feel that you need to.
	 // Developers, you may wish to add more fields to the form, in which case you must be sure to add them here.

	 $e_body = "$fist_name $last_name has signed up for promotions and is interested in $interest.\r\n\n";
	 $e_content = "Their details are:\r\n\n";
	 $e_details = "$first_name $last_name\n$address\n$address2\n$town\n$postcode\n\n$phone\n\n$email\r\n\n";

	 // Configuration option.
       	 // RIf you active phone number, swap the tags of $e-reply below to include phone number.
	 //$e_reply = "You can contact $name via email, $email or via phone $phone";
	 $e_reply = "You can contact them via email, $email";

         $msg = $e_body . $e_content . $e_details . $e_reply;

         mail($address, $e_subject, $msg, "From: $email\r\nReply-To: $email\r\nReturn-Path: $email\r\n");


	 // Email has sent successfully, echo a success page.

	 echo "<div id='succsess_page'>";
	 echo "<h1>Email Sent Successfully.</h1>";
	 echo "<p>Thank you <strong>$name</strong>, your message has been submitted to us.</p>";
	 echo "</div>";
                      
	}
}

         if(!isset($_POST['signup']) || $error != '') // Do not edit.
         {
?>

            <?php echo $error; ?>
            
            <form  method="post" action="">

            <input name="first_name" type="text" value="First Name" onfocus="if (this.value == this.defaultValue) {this.value='';}" onblur="if (this.value == '') {this.value = this.defaultValue;}" class="email"/>

		<br />
            <input name="last_name" type="text" value="Last Name" onfocus="if (this.value == this.defaultValue) {this.value='';}" onblur="if (this.value == '') {this.value = this.defaultValue;}" class="email"/>

		<br />
            <input name="address" type="text" value="Address" onfocus="if (this.value == this.defaultValue) {this.value='';}" onblur="if (this.value == '') {this.value = this.defaultValue;}" class="tel"/>

		<br />
            <input name="address2" type="text" value="Address Cont" onfocus="if (this.value == this.defaultValue) {this.value='';}" onblur="if (this.value == '') {this.value = this.defaultValue;}" class="tel"/>

		<br />
            <input name="town" type="text" value="Town" onfocus="if (this.value == this.defaultValue) {this.value='';}" onblur="if (this.value == '') {this.value = this.defaultValue;}" class="tel"/>

		<br />
            <input name="postcode" type="text" value="Postcode" onfocus="if (this.value == this.defaultValue) {this.value='';}" onblur="if (this.value == '') {this.value = this.defaultValue;}" class="tel"/>

		<br />
            <input name="phone" type="text" value="Tel number" onfocus="if (this.value == this.defaultValue) {this.value='';}" onblur="if (this.value == '') {this.value = this.defaultValue;}" class="tel"/>

		<br />
            <input name="email" type="text" value="Email address" onfocus="if (this.value == this.defaultValue) {this.value='';}" onblur="if (this.value == '') {this.value = this.defaultValue;}" class="tel"/>

            <br />
            <label>Please select area of interest</label>
            <select name="interest" class="interest">
              <option value="">Please select</option>
              <option value="The Club">The Club</option>
              <option value="Health & Fitness">Health & Fitness</option>
              <option value="Golf">Golf</option>
              <option value="Events">Events</option>
              <option value="Business">Business</option>
              <option value="Weddings">Weddings</option>
            </select>
            
            <br />
            
            <input name="signup" type="submit" class="submit" value="send" />

            </form>

<?php } 

?>            
</div>

Link to comment
Share on other sites

<div id="contact2">
<?php
//include the connect script
include "connect.php";

/*THIS VARIABLE IS WHAT TABLE YOU ARE USING...IF YOU USED MY SQL FILE, THEN YOUR DEFAULT TABLE*/
/*NAME SHOULD BE 'userv2' AND YOU DO NOT NEED TO CHANGE ANYTHING, BUT IF YOU MADE YOUR OWN TABLE,*/
/*CHANGE THIS VARIABLE.*/
	$tableName = "dataget";
	$error    = '';
        $first_name    = '';
	$last_name    = ''; 
        $address    = '';
        $address2  = ''; 
        $town = ''; 
        $postcode   = '';
	$phone   = '';
	$email = '';
	$interest = '';

	//grab all the usernames in the table
	$sql1 = mysql_query("SELECT * FROM $tableName WHERE email = '$email'");
	//get number of results from both queries
	$row1 = mysql_num_rows($sql1);

etc.....

<?php } 
?>            
</div>

 

you have declared $email to be empty, asked it to check in sql... then declared it as post value

Link to comment
Share on other sites

      //grab all the usernames in the table
      $sql1 = mysql_query("SELECT * FROM $tableName WHERE email = '$email'");

 

here you are asking WHERE email = '';

 

When you want to ask it WHERE email = '$_POST['email']';

 

although I recommend validating the POST['email'] before using it in a sql query  8)

Link to comment
Share on other sites

noticed you already have an email function to validate.

 

 

$phone   = '';
      $email = '';
      $interest = '';

 

replace with

$phone   = '';
      $email = $_POST['email'];
if(!isEmail($email)) {
           $error = '<div class="error_message">Attention! You have enter an invalid e-mail address, try again.</div>';
           $email = '';// remove posted email as is invalid and error is already set
}
      $interest = '';

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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