Jump to content

Registration form trying to add if empty thing to it... Page shows up white.


Russia

Recommended Posts

Hey guys I am trying to add form validation type of thing where it checks if the form was submitted with values in all of the fields. This is how it looks.

 



<?php

error_reporting(E_ALL);
ini_set('display_errors', '1');

include("config.php");








if (isset($_POST['username']) && isset($_POST['password']) && isset($_POST['email']) && isset($_POST['secQ']) && isset($_POST['secA'])) {


$username = mysql_real_escape_string($_POST['username']);
$secQ = mysql_real_escape_string($_POST['secQ']);
$secA = mysql_real_escape_string($_POST['secA']);
$password = $_POST['password'];
$email = $_POST['email'];




if (empty( $_POST['username'] || $_POST['password'] || $_POST['email'] || $_POST['secQ'] || $_POST['secA'] )) {
echo "form not fully filled, reshow first form";
}
else {






if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
  echo "<br><br>Valid email address.";
  mysql_query("INSERT INTO admin (username, password, email, secquestion, secanswer, sendemail) VALUES ( '$username', '$password', '$email', '$secQ', '$secA','1')") or die (mysql_error()); 
  echo "<br>Account created.";
}
else {
  echo "<br><br>Invalid email address.";
}

}// for if empty

}
?>


<html>

<style type="text/css">
label {
width:300px;    /*Or however much space you need for the form’s labels*/
    float:left;
}
</style>


<hr>
<form action="register2.php" method="post">

<div class=”field_container”><label>Username</label><input name="username" type="text" /></div>
<div class=”field_container”><label>Password</label><input type="password" value="" name="password" /></div>
<div class=”field_container”><label>Email</label><input name="email" type="text" /></div>
<div class=”field_container”><label>Choose a secret question</label>
<select name="secQ">
<option disabled selected value="0">Choose Secret Question</option>
<option value="1">What is your middle name?</option>
<option value="2">What is your mothers maiden name?</option>
<option value="3">What city were you born in?</option>
<option value="4">What is your favorite color?</option>
<option value="5">What year did you graduate from High School?</option>
<option value="6">What was the name of your first boyfriend/girlfriend?</option>
<option value="7">What is your favorite model of car?</option>
</select>
</div>
<div class=”field_container”><label>Enter a secret answer</label><input name="secA" type="text" /></div>
<div class=”field_container”><label> </label><input type="submit" value="Submit" /></div>



</form>


</html>

 

I added the:

if (empty( $_POST['username'] || $_POST['password'] || $_POST['email'] || $_POST['secQ'] || $_POST['secA'] )) {

 

part to it, but I think I might of done it wrong, so if someone can help me fix the code because no errors are showing up..

 

Id really appreciate the help! :)

The page is still white,

 

Look at my code and tell me if I maybe made a mistake with the elseif or if statements please. :)

 

<?php

error_reporting(E_ALL);
ini_set('display_errors', '1');

include("config.php");








if (isset($_POST['username']) && isset($_POST['password']) && isset($_POST['email']) && isset($_POST['secQ']) && isset($_POST['secA'])) {


$username = mysql_real_escape_string($_POST['username']);
$secQ = mysql_real_escape_string($_POST['secQ']);
$secA = mysql_real_escape_string($_POST['secA']);
$password = $_POST['password'];
$email = $_POST['email'];




//if (empty( $_POST['username'] || $_POST['password'] || $_POST['email'] || $_POST['secQ'] || $_POST['secA'] )) {
if ( empty( $_POST['username']) || empty($_POST['password']) || empty($_POST['email']) || empty($_POST['secQ']) || empty($_POST['secA']) ) {

echo "form not fully filled, reshow first form";
}
elseif {






if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
  echo "<br><br>Valid email address.";
  mysql_query("INSERT INTO admin (username, password, email, secquestion, secanswer, sendemail) VALUES ( '$username', '$password', '$email', '$secQ', '$secA','1')") or die (mysql_error()); 
  echo "<br>Account created.";
}
elseif {
  echo "<br><br>Invalid email address.";
}

}// for if empty

}
?>






<html>

<style type="text/css">
label {
width:300px;    /*Or however much space you need for the form’s labels*/
    float:left;
}
</style>


<hr>
<form action="register2.php" method="post">

<div class=”field_container”><label>Username</label><input name="username" type="text" /></div>
<div class=”field_container”><label>Password</label><input type="password" value="" name="password" /></div>
<div class=”field_container”><label>Email</label><input name="email" type="text" /></div>
<div class=”field_container”><label>Choose a secret question</label>
<select name="secQ">
<option disabled selected value="0">Choose Secret Question</option>
<option value="1">What is your middle name?</option>
<option value="2">What is your mothers maiden name?</option>
<option value="3">What city were you born in?</option>
<option value="4">What is your favorite color?</option>
<option value="5">What year did you graduate from High School?</option>
<option value="6">What was the name of your first boyfriend/girlfriend?</option>
<option value="7">What is your favorite model of car?</option>
</select>
</div>
<div class=”field_container”><label>Enter a secret answer</label><input name="secA" type="text" /></div>
<div class=”field_container”><label> </label><input type="submit" value="Submit" /></div>



</form>


</html>

Nevermind, I was using the browser on my phone and didn't notice that you had commented the line out. What you have now is an elseif with no conditions for it.

echo "form not fully filled, reshow first form";
}
elseif {

 

elseif what?

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.