Create a registration page with php

  You are currently not logged in. You can view the forums, but cannot post messages. Log In | Register

13-Apr-17 16:45
Hi, good day...

I'm new to .PHP but tried to create a members page for a website I manage... It worked "O.K" until I added a select option field in it.

Now it won't submit no matter what I do, however it'll submit the form with only a new email address, but won't save it in the database...

Please any help with these two request will be greatly appreciated.


<?php

$form_has_been_submited = $_POST['form_has_been_submited'];
if($form_has_been_submited == 1)

{
// define variables and set to empty values
$genderErr = $nfErr = $nlErr = $emailErr = $dobErr = $deptErr = $functErr = $phoneErr = $pwErr = $pwvErr = $agreementErr = "";
$gender = $nf = $nl = $email = $dob = $dept = $funct = $phone = $pw = $pwv = $agreement = $mailing = "";

function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}

if ($_POST["registerbtn"]) {

//Gender selection
if (empty($_POST["gender"])) {
$genderErr = "Gender is required";
} else {
$gender = test_input($_POST["gender"]);
}

//First Name selection
if (empty($_POST["nf"])) {
$nfErr = "Name is required";
} else {
$nf = test_input($_POST["nf"]);

// check if name only contains letters and whitespace
if (!preg_match("/^[a-zA-Z]*$/",$nf)) {
$nfErr = "Only letters allowed";
}
}

//Last Name selection
if (empty($_POST["nl"])) {
$nlErr = "Last Name is required";
} else {
$nl = test_input($_POST["nl"]);

// check if Last name only contains letters and whitespace
if (!preg_match("/^[a-z A-Z]*$/",$nl)) {
$nlErr = "Only letters and white space allowed";
}
}

//e-mail selection
if (empty($_POST["email"])) {
$emailErr = "Email is required";
} else {
$email = test_input($_POST["email"]);

// check if e-mail address is well-formed
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$emailErr = "Invalid email format";
}
}

//Birthday selection
if (empty($_POST["dob"])) {
$dobErr = "Birthday is required";
} else {
$dob = test_input($_POST["dob"]);

// Check birtday format
if ($dob > date("m/d/Y", mktime(0, 0, 0, date('m'), date('d'), date('Y') - 21))) {
}
}

//ID type selection
if (empty($_POST["idtype"])) {
$idtypeErr = "ID type is required";
} else {
$idtype = test_input($_POST["idtype"]);
}

//ID nr selection
if (empty($_POST["idnr"])) {
$idnrErr = "ID nr is required";
} else {
$idnr = test_input($_POST["idnr"]);

// check if name only contains letters and whitespace
if (!preg_match("/^[0-9a-zA-Z]*$/",$idnr)) {
$idnrErr = "Only letters and numbers allowed";
}
}

//Employer selection
if (empty($_POST["employer"])) {
$employerErr = "employer is required";
} else {
$employer = test_input($_POST["employer"]);
}

//Department selection
if (empty($_POST["dept"])) {
$deptErr = "Department is required";
} else {
$dept = test_input($_POST["dept"]);

// check if department only contains letters and whitespace
if (!preg_match("/^[a-z A-Z]*$/",$dept)) {
$deptErr = "Only letters and white space allowed";
}
}

//Function selection
if (empty($_POST["funct"])) {
$functErr = "Function is required";
} else {
$funct = test_input($_POST["funct"]);

// check if function only contains letters and whitespace
if (!preg_match("/^[a-zA-Z]*$/",$funct)) {
$functErr = "Only letters and white space allowed";
}
}

//Phone number selection
if (empty($_POST["phone"])) {
$phoneErr = "Phone number is required";
} else {
$phone = test_input($_POST["phone"]);

// check if phone nr is well-formed
if (!preg_match("/^[0-9]{4}[0-9]{3}[0-9]{4}$/",$phone)) {
$phoneErr = "invalid phone number input";
}
}

//Address selection
if (empty($_POST["address"])) {
$addressErr = "Address is required";
} else {
$address = test_input($_POST["address"]);

// check if address only contains letters and whitespace
if (!preg_match("/^[a-z A-Z 0-9]*$/",$address)) {
$addressErr = "Only letters, whitespace and numbers allowed";
}
}

//Start day selection
if (empty($_POST["sday"])) {
$sdayErr = "Start day is required";
} else {
$sday = test_input($_POST["sday"]);

// Check start day format
if ($sday > date("m/d/Y", mktime(0, 0, 0, date('m'), date('d'), date('Y') - 21))) {
}
}

//Password selection
if (empty($_POST["pw"])) {
$pwErr = "password is required";
} else {
$pw = test_input($_POST["pw"]);

// check if password is well-formed
if (!preg_match("/^(?=.*\d)(?=.*[A-Z])(?=.*[a-z])[0-9A-Za-z!@#$%]{5,12}$/",$pw)) {
$pwErr = "Password must contain 5 characters, including 1 upper and lowercase letter and 1 number";
}
}

if (empty($_POST["pwv"])) {
$pwvErr = "password is required";
} else {
$pwv = test_input($_POST["pwv"]);

// check if passv is well-formed
if ($pw !== $pwv){
$pwvErr = "Your passwords did not match";
}
}

//User Agreement selection
if (empty($_POST["agreement"])) {
$agreementErr = "Agreement is required";
} else {
$agreement = test_input($_POST["agreement"]);
}

//Mailing list selection
if (empty($_POST["mailing"])) {
$mailing = "";
} else {
$mailing = test_input($_POST["mailing"]);
}


//Connect to database
require ("connect.php");


// make sure sure email is not in database
$query = mysql_query ("SELECT * FROM users WHERE email = '$email'");
$numrows = mysql_num_rows ($query);

if ($numrows == 0){
}

else
$emailErr = "That E-mail is aleady registered";


$pw = md5 (md5("HEHEes57f".$pw."kgjtfft6875"));
$date = date ("F d, Y");
$code = md5 (rand ());
$ip = $_SERVER['REMOTE_ADDR'];
$gender = $_POST['gender'];

// if all is OK, submit & send me email
if(($genderErr == "")&&($nfErr == "")&&($nlErr == "")&&($emailErr == "")&&($dobErr == "")&&($idtypeErr == "")&&($idnrErr == "")&&($employerErr == "")&&($deptErr == "")&&($functErr == "")&&($phoneErr == "")&&($addressErr == "")&&($sdayErr == "")&&($pwErr == "")&&($pwvErr == "")&&($agreementErr == "")){


mysql_query ("INSERT INTO users VALUES ('', '', '', '$gender', '$nf', '$nl', '$email', '$dob', '$idtype', '$idnr', '$employer','$dept', '$funct', '$phone', '$address', '$sday', '$pw', '$agreement', '$mailing', '$code', '$date', '$ip', '')");
}


$query = mysql_query ("SELECT * FROM users WHERE email = '$email'");
$numrows = mysql_num_rows ($query);


if ($numrows == 1){

{
// if all is OK, send me an email
$ip=$_SERVER['REMOTE_ADDR'];
$zones = array();
$zones['America/Puerto_Rico'] = 'Atlantic Standard Time (ATS)';
$today = date ("F j, Y, g:i:sa");

$message = "";
$message .= "New regestry on http://www.abvo.sx \n";
$message .= "\n";
$message .= "From: $email Date: $today IP(address): $ip \n";
$message .= " \n";
$message .= " \n";
$message .= "By: $gender $nf $nl \n";
$message .= " \n";
$message .= "Phone: $phone \n";
$message .= " \n";
$message .= " \n";
$message .= "Message: $gender $nf $nl, just registered as a member on http://www.abvo.sx \n";
$message .= " \n";
$message .= "The start date for contribution debit is $sday \n";
$message .= " \n";
$message .= " \n";

$youremail = "info@abvo.sx";

// Send email order to you...
$headers = "From: $email\r\n";
$headers .="X-Mailer: PHP Mail generated by Benjamin Boyrard\r\n";
$subject = "New Registration on ABVO Sint Maarten";
mail($youremail, $subject, $message, $headers);}

// Send email to Registree...
$site = "http://www.abvo.sx/site";
$webmaster = "ABVO Sint Maarten <donotreply@abvo.sx>";
$headers = "From: $webmaster";
$subject = "Activate Your Account";
$message = "Thanks for registering with ABVO St. Maarten. \n";
$message .= "Your contribution will start for the period of $sday. \n";
$message .= "Click the link below to activate your account. \n";
$message .= "\n";
$message .= "$site/forms/activate.php?email=$email&code=$code \n";
$message .= "\n";
$message .= "You must activate your account to login";

if (mail ($email, $subject, $message, $headers) ){
$errormsg = "You have been registered you must activate your account from the activation link sent to <b>$email</b>";
$gender = "";
$nf = "";
$nl = "";
$email = "";
$dob = "";
$idtype = "";
$idnr = "";
$employer = "";
$dept = "";
$funct = "";
$phone = "";
$address = "";
$sday = "";
$agreement = "";
$mailing = "";
}

else
$errormsg = "An error has occured. Your activation email was not sent";
}

else
$errormsg = "An error has occured. Your account was not created";
}

mysql_close();
}
?>

<div>
<form name="register" action="register.php" method="post" enctype="multipart/form-data">
<table>
<tr>
<td colspan="2" class="error"><p>* required field.</p></td>
</tr>

<tr>
<td>Gender:</td>
<td><input type="radio" name="gender" <?php if (isset($gender) && $gender=="Mr") echo "checked";?> value="Mr">Mr
<input type="radio" name="gender" <?php if (isset($gender) && $gender=="Mrs") echo "checked";?> value="Mrs">Mrs
<input type="radio" name="gender" <?php if (isset($gender) && $gender=="Ms") echo "checked";?> value="Ms">Ms</td>
<td class="error">* <?php echo $genderErr;?></td>
</tr>

<tr>
<td>First name:</td>
<td><input type="text" name="nf" value="<?php echo $nf;?>" onClick="if(this.value=='First name:'){this.value=''};" onBlur="if(this.value==''){this.value='First name:'};"/></td>
<td class="error">* <?php echo $nfErr;?></td>
</tr>

<tr>
<td>Last name:</td>
<td><input type="text" name="nl" value="<?php echo $nl;?>" onClick="if(this.value=='Last name:'){this.value=''};" onBlur="if(this.value==''){this.value='Last name:'};"/></td>
<td class="error">* <?php echo $nlErr;?></td>
</tr>

<tr>
<td>E-mail:</td>
<td><input type="text" name="email" value="<?php echo $email;?>" onClick="if(this.value=='E-mail:'){this.value=''};" onBlur="if(this.value==''){this.value='E-mail:'};"/></td>
<td class="error">* <?php echo $emailErr;?></td>
</tr>

<tr>
<td>Birthday:</td>
<td><input type="date" name="dob" value="<?php echo $dob;?>" onClick="if(this.value=='Birthday:'){this.value=''};" onBlur="if(this.value==''){this.value='Birthday:'};"/></td>
<td class="error">* <?php echo $dobErr;?></td>
</tr>

<tr>
<td>ID Type:</td>
<td><input type="radio" name="idtype" <?php if (isset($idtype) && $idtype=="PP") echo "checked";?> value="PP">Passport
<input type="radio" name="idtype" <?php if (isset($idtype) && $idtype=="DRL") echo "checked";?> value="DRL">Drivers license
<td class="error">* <?php echo $idtypeErr;?></td>
</tr>

<tr>
<td>ID nr:</td>
<td><input type="text" name="idnr" value="<?php echo $idnr;?>" onClick="if(this.value=='ID nr:'){this.value=''};" onBlur="if(this.value==''){this.value='ID nr:'};"/></td>
<td class="error">* <?php echo $idnrErr;?></td>
</tr>

<tr>
<td>Employer:</td>
<td><select name="employer">
<option value="" Selected>Pick one</option>
<option value="GOV">Gov</option>
<option value="PJIAE">PJIAE</option>
<option value="WinAir">WinAir</option>
<option value="Kooyman">Kooyman</option>
<option value="SMPA">SMPA</option>
<option value="SZV">SZV</option>
<option value="PanAmerican">PanAmerican</option>
</select></td>
<td class="error">* <?php echo $employerErr;?></td>
</tr>

<tr>
<td>Department:</td>
<td><input type="text" name="dept" value="<?php echo $dept;?>" onClick="if(this.value=='Department:'){this.value=''};" onBlur="if(this.value==''){this.value='Department:'};"/></td>
<td class="error">* <?php echo $deptErr;?></td>
</tr>

<tr>
<td>Function:</td>
<td><input type="text" name="funct" value="<?php echo $funct;?>" onClick="if(this.value=='Function:'){this.value=''};" onBlur="if(this.value==''){this.value='Function:'};"/></td>
<td class="error">* <?php echo $functErr;?></td>
</tr>

<tr>
<td>Telephone nr:</td>
<td><input type="text" name="phone" value="<?php echo $phone;?>" onClick="if(this.value=='17211231234'){this.value=''};" onBlur="if(this.value==''){this.value='ex.17211231234'};"/></td>
<td class="error">* <?php echo $phoneErr;?></td>
</tr>

<tr>
<td>Address:</td>
<td><input type="text" name="address" value="<?php echo $address;?>" onClick="if(this.value=='Address:'){this.value=''};" onBlur="if(this.value==''){this.value='ex.Address:'};"/></td>
<td class="error">* <?php echo $addressErr;?></td>
</tr>

<tr>
<td>Start date:</td>
<td><input type="date" name="sday" value="<?php echo $sday;?>" onClick="if(this.value=='Start date:'){this.value=''};" onBlur="if(this.value==''){this.value='Start date:'};"/></td>
<td class="error">* <?php echo $sdayErr;?></td>
</tr>

<tr>
<td>Password:</td>
<td><input type="password" name="pw" value="" onClick="if(this.value==''){this.value=''};" onBlur="if(this.value==''){this.value=''};"/></td>
<td class="error">* <?php echo $pwErr;?></td>
</tr>

<tr>
<td>Re-type Password:</td>
<td><input type="password" name="pwv" value="" onClick="if(this.value==''){this.value=''};" onBlur="if(this.value==''){this.value=''};"/></td>
<td class="error">* <?php echo $pwvErr;?></td>
</tr>

</table>

<table>

<tr>
<td><input type = "checkbox" name = "agreement" <?php if (isset($agreement) && $agreement == "1") echo "checked";?> value="1"/></td>
<td>I agree with the <a title="Terms &amp; Conditions" target="_blank" href="http://www.abvo.sx/site/pages/terms.php">Terms &amp; Conditions</a></td>
<td class="error">* <?php echo $agreementErr;?></td>
</tr>

<tr>
<td><input type= "checkbox" name= "mailing" <?php if (isset($mailing) && $mailing == "1") echo "checked";?> value="1"/></td>
<td>Would you like to receive E-mails from ABVO SXM?</td>
</tr>

</table>
<div><input type="hidden" name="form_has_been_submited" value="1" /></div>
<div><input type="submit" name="registerbtn" value="Register" title="Register" alt="Register"/></div>
<div class="error"><?php echo $errormsg;?></div>
</form>
<br />
16-Apr-17 07:56
This;
"Now it won't submit no matter what I do, however it'll submit the form with only a new email address"

Does not make logical sense, "won't submit" and "it will submit with" are contradictions so it can ONLY be one of these.

--
Chris.
So long, and thanks for all the fish.
http://webmaster-talk.eu/
16-Apr-17 10:56
G'afternoon,

Thank you for your quick reply,

You're right, I guess I got confused with my desires, but I meant to have the form only submit if all the required fields are filled in and not only a new email.

Also could I please possibly get some help clearing up the issue with submitting the <select> option part of the form, maybe the earlier .php conditions are making it that it isn't submitted but I wanted to make sure the <select> option wasn't left blank.

Kind regards,

 
New posts
Old posts

Follow Elated