Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6765229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:41:16+00:00 2026-05-26T14:41:16+00:00

<?php $gender = 0; if (($gender != 0) || ($gender != 1)) { die(‘error:Must

  • 0
<?php
$gender = 0;
if (($gender != 0) || ($gender != 1))
{
    die('error:Must select a gender.');
}
?>

This should give a error if the gender is anything other than 1 or 0. So if i gave 5 it should die. If i gave it 1 it should not die. If i give it 0 it should not die.

I was thinking about a few work arounds

<?php
$gender = 0;
if ($gender == 0)
{
//number is okay
}
else if ($gender == 1)
{
//number is okay
}
else
{
die('error:Must select a gender.');
}
?>

Well that looks sloppy and it would work or i could create a array with 0 and 1 and check if its in it or not. Kinda overkill i think.

Not sure what i’m doing wrong.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:41:17+00:00Added an answer on May 26, 2026 at 2:41 pm

    You’re using the wrong boolean operator:

     if (($gender != 0) || ($gender != 1)) {
     }
    

    This will be entered if gender is 0, too, because it isn’t 1, and vice versa. What you need to do is:

     if (($gender != 0) && ($gender != 1)) {
     }
    

    Look at this table:

    gender  A (gender != 0)    B (gender != 1)     A || B     A && B
    ----------------------------------------------------------------
    0       false              true                true       false
    1       true               false               true       false
    5       true               true                true       true
    

    Also note Joshua’s suggestion in the comments:

    if (($gender == 0) || ($gender == 1)) {
        /* number is ok */
    } else {
        die();
    }
    

    which is a bit longer, but more readable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble with this error in php: Parse error: syntax error, unexpected $end
I have this code (CodeIgniter): <tr> <td width=80>Gender*:</td> <td> <?php echo form_dropdown('gender', $gender_select, $gender_val);
I have a registration module with PHP validation. This coding shows the error and
Example to save gender <form action=save.php?id=<?=$id?> method=post> <p><label><input name=gender type=radio value=male <?php if($gender=='male'){?>checked=checked<? }?>
PHP, as we all know is very loosely typed. The language does not require
I have two pages like reg.php and profile.php. in reg.php have a field gender
Am I doing this right? I went to look at some old PHP code
I've tried this: http://be.php.net/manual/en/function.mysql-list-fields.php , but there's too much detail here. What I'm looking
This is my jQuery... $.ajax({ type: 'POST', url: 'http://adamscarter.co.uk/daily/facebook/savefbprofile.php', data: {'fb_id': fb_id, 'fbusername': fbusername,
I'm new to JSON and really struggling with this. I've read countless other posts

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.