-1

I have a php form and i need 4 field data to be submitted.

  1. Name
  2. Email
  3. Password
  4. Mobile

Now i have to check if all the above data is available or not.

For debugging purpose i am use $_GET below

if (!empty($_GET['name']) or !empty($_GET['email']) or !empty($_GET['password']) or !empty($_GET['mobile'])) {
    $response = array(
        'status' => 'OK',
        'error' => '1',
        'message' => 'Registered successfully. Please check your email for activation details',
        'data' => '');
} else {
    $response = array(
        'status' => 'NOK',
        'error' => '1',
        'message' => 'There was some error please try again.',
        'data' => '');
}

The above is not able to validate the form properly.

6
  • i am not able to get this to work
    – Harsha M V
    Commented May 6, 2013 at 7:39
  • Use array_key_exists instead of empty. Also take a look at the filter_var function
    – HamZa
    Commented May 6, 2013 at 7:41
  • 1
    To ask a question you have to explain desired result. At least Commented May 6, 2013 at 7:41
  • why you use $_GET instead $_POST?
    – Plipus Tel
    Commented May 6, 2013 at 7:42
  • @PhilipsTel to test i am using GET i have mentioned in the question
    – Harsha M V
    Commented May 6, 2013 at 7:48

2 Answers 2

6

It is important to use and in the condition, not or:

if (!empty($_GET['name']) and !empty($_GET['email']) and !empty($_GET['password']) and !empty($_GET['mobile'])) {
3

Most forms are submitted using method="POST" which means on the PHP side you should be using $_POST instead of $_GET.

You also have a logic error, you want to proceed only if they are all filled in, therefore you want to use and instead of or.

Not the answer you're looking for? Browse other questions tagged or ask your own question.