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

Link to comment
Share on other sites

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>

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.