Jump to content

Saturday morning PHP


JasonBruce88

Recommended Posts

I have a form that connects to a MySQL data base but for some reason when I submit the form, only pressing the button once, the data is added to the form twice? Anybody have any ideas on this?

 

Here is the code

 

HTML

<?php include("inc/headerlogin.php"); ?>
<form action="submited.php" method="post"> 
<fieldset>
    <legend>Customer details</legend>                      
      <p>
<label for="FirstName">First name</label>
  <input type="text" name="FirstName" value="" id="FirstName">
      </p>
            
      <p>
 <label for="LastName">Last name</label>
            <input type="text" name="LastName" value="" id="LastName">
      </p>

      <p>
<label for="Title">Title</label>
            <select name="Title" id="Title">
	<option>Mr</option>
	<option>Mrs</option>
	<option>Miss</option>
	<option>Ms</option>
	<option>Dr</option>
	<option>Rev</option>
	<option>Sir</option>
    </select>
      </p>

      <p>
<label for="PN1">Phone</label>
          <input type="text" name="PN1" value="" id="PN1">
    <span>(primary)</span>
      </p>

      <p>
<label for="PN2">Phone 2</label>
          <input type="text" name="PN2" value="" id="PN2">
    <span>(secondary)</span>
      </p>
      
      <p>
<label for="UserTypeCode">I am a:</label>
  <select name="UserTypeCode">
    <option name="Landlord" value="1"> Landlord </option>
    <option name="Tenant" value="2"> Tenant </option>
    <option name="Engineer" value="3"> Engineer </option>
  </select>


      <p>
<label for="Email">Email</label>
           <input type="text" name="Email" value="" id="Email">
      </p>

      <p>
<label for="Password">Password</label>
  <input type="Password" name="Password" value="" id="Password">
      </p>

      <p>
<label for="Password2">Password</label>
  <input type="Password" name="Password2" value="" id="Password2">
      </p>


   <p class="alignright">
     <input type="submit" name="submit" value="Confirm details" class="button">
   </p>
</fieldset>
</form>

<?php include("inc/footer.php"); ?>

 

PHP:

<?php include("inc/headerlogin.php");
$con = mysql_connect("*", "*", "*") or
die(mysql_error("A MySQL error has occurred"));
mysql_select_db("*") or
die(mysql_error("A MySQL error has occurred"));

if (!$con)
{
die('Could not connect: ' . mysql_error());
}

if (isset($_POST['submit'])) {
  //ensures fields are not blank
  if (!$_POST['Email'] | !$_POST['Password'] | !$_POST['Password2']) {
     die('You did not complete all of the required fields'); 
  }

//Checks if email address is allready in use
  if (!get_magic_quotes_gpc()) {
    $_POST['Email'] = addslashes($_POST['Email']);
  }
  $emailcheck = $_POST['Email'];
  $chek = mysql_query("SELECT * FROM client WHERE Email = '$emailcheck'")
  or die(mysql_error());
  $check2 = mysql_num_rows($chek);

  //notifys if email address is already registered
  if ($check2 != 0) {
  die('Sorry, the Email Address '.$_POST['Email'].' is already in use. Please try again');
  }

  //makes sure passwords match
  if ($_POST['Password'] !=$_POST['Password2']) {
  die('The passwords you have entered do not match.Please try again');
  }

  //encrypt the users password
  $_POST['Password'] = md5($_POST['Password']);
  if (!get_magic_quotes_gpc()) {
     $_POST['Password'] = addslashes($_POST['Password']);
     $_POST['Email'] = addslashes($_POST['Email']);
  }

  //insert into database
  $insert = "INSERT INTO client (FirstName, LastName, Title, PN1, PN2, Email, Password, UserTypeCode)
      VALUES ('".$_POST['FirstName']."', '".$_POST['LastName']."', '".$_POST['Title']."', 
	      '".$_POST['PN1']."', '".$_POST['PN2']."', '".$_POST['Email']."',  
	      '".$_POST['Password']."',  '".$_POST['UserTypeCode']."')";
  $add_member = mysql_query($insert);
  

if (!mysql_query($insert,$con))

{
die('Error: ' . mysql_error());
}
echo "Thank you, you have registered - you may now login";

}
mysql_close($con)

?>

Link to comment
https://forums.phpfreaks.com/topic/195103-saturday-morning-php/
Share on other sites

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.