Jump to content

My form is not working...why...pls help


jd2007

Recommended Posts

<?php

/*Use of Sessions*/
if(!session_id())
session_start();

header("Cache-control: private"); //avoid an IE6 bug (keep this line on top of the page)

if ( isset($_POST["name"]) && isset($_POST["location"]) && isset($_POST["age"]) && isset($_POST["username"]) && isset($_POST["password"]) && isset($_POST["cpass"]) && isset($_POST["email"]))
{
if (!(isset($_POST["accept"])&&$_POST["accept"]=="accept"))
{
echo "You must accept the <a href=''>Terms and Conditions</a> that apply if you want to register.";
exit;
}
else if (isset($_POST["accept"])&&$_POST["accept"]=="accept")
{
   if ($_POST["password"]==$_POST["cpass"])
   {
    if (ereg("^[a-zA-Z0-9\_\-\.]+@[a-zA-Z]+\.[a-zA-Z\.\-]+$",$_POST["email"]))
    {
     //does some work (i never code this yet)
    }
    else
    {
     echo "The e-mail you have entered is not valid. Please enter a valid e-mail.";
     exit;
    }
   }
   else if ($_POST["password"]!==$_POST["cpass"])
   {
    echo "Passwords do not match.";
    exit;
   }
   else {}
}  
}
else if ( !isset($_POST["name"]) || !isset($_POST["location"]) || !isset($_POST["age"]) || !isset($_POST["username"]) || !isset($_POST["password"]) || !isset($_POST["cpass"]) || !isset($_POST["email"]))
{
if (!(isset($_POST["accept"])&&$_POST["accept"]=="accept"))
{
echo "You must fill in all fields and accept the <a href=''>Terms and Conditions</a> that apply if you want to register.";
exit;
}
else if (isset($_POST["accept"])&&$_POST["accept"]=="accept")
{
echo "Plese fill in all fields.";
exit;

}
else{}
}
else {}

?>

 

the code above is executed when submit is clicked at the form inside this code:

 

<html>
<head>
<title>Register</title>
</head>
<body>
<form method="post" action="registration.php">
<h2>Register</h2><br><br>
<hr>
<b><u>1. Personal Details</u></b><br><br>
Name: <input type="text" name="name"><br><br>
Location: <input type="text" name="name"><br><br>
Age: <input type="text" name="age"><br><br>
<b><u>1. Account Details</u></b><br><br>
E-mail: <input type="text" name="email"><br><br>
Username: <input type="text" name="username"><br><br>
Password: <input type="password" name="password"><br><br>
Confirm Password: <input type="password" name="cpass"><br><br>
<hr>
<hr>
<input type="checkbox" name="accept" value="accept"> I accept the <a href="">Terms and Conditions</a> that apply.
<hr>
<input type="submit" value="Register">
</form>
</body>
</html>

 

When all fields are filled and terms and condition are accepted by checking the checkbox, it checks wheter passwords match, if not, it tells the user...if it matches, it then checks wheter e-mail is valid, it does some work (i never code that yet)...if not, tells the user, the problem is after filling all fields and accepting terms and condition, it doesn't do what i want...it shows "Please fill in all fields"

Link to comment
https://forums.phpfreaks.com/topic/60149-my-form-is-not-workingwhypls-help/
Share on other sites

ok here is a hint... only check if one of the forms from the field is set, initially.  if one of them is set, then you can assume that the rest of them are as well (though they may be null)

 

you also have way too many unnecessary else-if statements.  perhaps you want them to just be else statements?

you also have else statements that do nothing... you can just omit those.

 

if you clean up your code a bit we may be able to check it.

ok...i cleaned my code...can u please check wheter everything is alright ?

 

<?php

/*Use of Sessions*/
if(!session_id())
session_start();

header("Cache-control: private"); //avoid an IE6 bug (keep this line on top of the page)


if ( isset($_POST["name"]) || isset($_POST["location"]) || isset($_POST["age"]) || isset($_POST["username"]) || isset($_POST["password"]) || isset($_POST["cpass"]) || isset($_POST["email"]))
{
if (!(isset($_POST["accept"])&&$_POST["accept"]=="accepted"))
{
echo "You must accept the <a href=''>Terms and Conditions</a> that apply if you want to register.";
exit;
}
else
{
   if ($_POST["password"]==$_POST["cpass"])
   {
    if (ereg("^[a-zA-Z0-9\_\-\.]+@[a-zA-Z]+\.[a-zA-Z\.\-]+$",$_POST["email"]))
    {
     
    }
    else
    {
     echo "The e-mail you have entered is not valid. Please enter a valid e-mail.";
     exit;
    }
   }
   else
   {
    echo "Passwords do not match.";
    exit;
   }
   
}  
}
else
{
if (!(isset($_POST["accept"])&&$_POST["accept"]=="accepted"))
{
echo "You must fill in all fields and accept the <a href=''>Terms and Conditions</a> that apply if you want to register.";
exit;
}
else
{
echo "Plese fill in all fields.";
exit;

}

}


?>

 

it works now but if i want to check all fields, pls give me a hint on how to do it ? just a hint...thanks...

thanks for your help...the problem was the location field's textbox's name was not location...

<html>
<head>
<title>Register</title>
</head>
<body>
<form method="post" action="registration.php">
<h2>Register</h2><br><br>
<hr>
<b><u>1. Personal Details</u></b><br><br>
Name: <input type="text" name="uname"><br><br>
Location: <input type="text" name="location"><br><br>
Age: <input type="text" name="age"><br><br>
<b><u>1. Account Details</u></b><br><br>
E-mail: <input type="text" name="email"><br><br>
Username: <input type="text" name="username"><br><br>
Password: <input type="password" name="password"><br><br>
Confirm Password: <input type="password" name="cpass"><br><br>
<hr>
<hr>
<input type="checkbox" name="accept" value="accepted"> I accept the <a href="">Terms and Conditions</a> that apply.
<hr>
<input type="submit" value="Register">
</form>
</body>
</html>

so, php could not find such textbox and it did not work...now, i still check all fields if it is filled and it still works...thank you..

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.