Unless register_globals is on (which it really should not be), you'll need to reference the values from the $_POST array:
PHP Code:
if ( (trim($_POST['name'])=="") || (trim($_POST['gender'])=="") ||
If that's not the case, or if you've copied the $_POST array vales to scalar variables, then the only other thing is to double-check that you don't have a spelling error somewhere, as comparing an uninitialized variable to "" will always return true.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
PS: a cleaner way to check the required values in the $_POST array might be:
PHP Code:
$required = array('name', 'gender', 'email', 'age', 'add01', 'add02', 'city', 'country', 'post_code');
foreach ($required as $ix)
{
if(empty(trim($_POST[$ix])))
{
echo "Error.. General Information is not complete!";
exit();
}
}
Also, should "add02" be required? (Usually this is an optional field for things like apartment numbers.)
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
i tried this but is now comes up with a parse error
You should give a bit more code. The error is not always on the line php indicates it is.
really dont know why my original code doesnt work
Because you're using old-fashioned code. It only works if the register_globals setting is switched on, which is often not the case. (read the two links i posted earlier)
When you can't figure out why something like that is working, it's often useful to add some temporary debug code. For instance, you might want to echo out each of the variables be checked in your if statement to see what values they have. Then if only one of them is coming up empty, you've narrowed down the problem and know where to focus your attention.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Parse error: parse error, unexpected '{' in line 32
So, what does this error tell you? That on line 32 PHP encounters a { where it didn't expect one. If it expected something else, you probably didn't close a certain delimiter. So, first step is to use color-coding:
PHP Code:
if (
(trim($_POST['name']) == "") || (trim($_POST['gender']) == "") || (trim($_POST['email']) == "") ||
(trim($_POST['age']) == "") || (trim($_POST['add01']) == "") || (trim($_POST['add02']) == "") ||
(trim($_POST['city']) == "") || (trim($_POST['country']) == "") || (trim($_POST['post_code']) == "")
)
{
echo "Error.. General Information is not complete!";
exit();
}
else if ( (trim($_POST['user_id']) == "") || (trim($_POST['pass_id']) == "") || (trim($con_pass_id)=="") )
{
echo "Error.. Login Information is not complete!";
exit();
}
else if ( (trim($_POST['card_type']) == "") || (trim($_POST['card_no']) == "") || (trim($_POST['expiry_date']) == ""))
{
echo "Error.. Credit Card Information is not complete!";
exit();
}
else if (trim($_POST['phone_no'] == "")
{
echo "Error.. Contact Information is not complete!";
exit();
}
else if (trim($_POST['con_pass_id'] != (trim($_POST['pass_id']) )
{
echo "Error.. Two Passwords do not matched!";
exit();
}
else
{
echo "Registration Successful! <br /> Enjoy Your Shopping";
exit();
}
If you forgot a double quote, for example, with colorcoding you would see this immediately. At first glance this appears not to be the case though
As you can see, i also indented your code. This is a very important practice that helps debugging a lot. Furthermore, consistancy in your code is important too. In your code for example, you sometimes put the { on the same line as the (else)if and sometimes on the line below it. That makes it very hard to read and track down errors. Better choose one or the other.
A final point of critic: don't use so many exits. If you keep using it this way, you'll come to a point where you have a very big piece of code and a blank screen and no way of finding out what went wrong where. It's much better to force your code down the right path by using things like if/else structures.
Now, how to find this bug. As i mentioned before: the most likely mistake is that you forgot to 'close ' something. So, start by the line directly above it. Nothing supsicious there. The line above that: there's double quotes ... but they seem to be ok too. On the line above that there's some single quotes and also quite a lot of (). The single quotes seem to be ok, so count the amount of ( and compare that with the amount of ).
etc. etc.
else if (trim($_POST['con_pass_id'] != (trim($_POST['pass_id']) ) {
...should be...
PHP Code:
else if (trim($_POST['con_pass_id']) != trim($_POST['pass_id']) ) {
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Bookmarks