Jump to content

if statement should definately work, but doesn't!


deed02392

Recommended Posts

<?php
   if (($_GET['ID']) == '18' || '9' || '13')
   
   echo ("<span class=buy>Sorry, this picture cannot be ordered currently.</span>");
      
   else 
   echo "<input type=image src=image/misc/btn_buynow_SM.gif border=0 name=submit alt=Click here to pay now!>";
    
   ?>

 

This code is meant to say, if the picture is either number 18, 9, or 13, then show they can't buy the picture, rather than the submit button if it equals anything else. however, no matter what, it ALWAYS shows that they can't buy the picture, even if ID=1 for example! I've looked at so many help website and they all show this format for else if statements. It just doesn't make sense, because, in theory, this is correct, right?

Link to comment
Share on other sites

I think you want:

<?php
   if ($_GET['ID'] == '18' || $_GET['ID'] == '9' || $_GET['ID'] == '13')
   
   echo ("<span class=buy>Sorry, this picture cannot be ordered currently.</span>");
      
   else 
   echo "<input type=image src=image/misc/btn_buynow_SM.gif border=0 name=submit alt=Click here to pay now!>";
    
   ?>

 

I'm pretty sure it was reading if (id = 18) or 9 or 13. 9 is 9 and 13 is 13 so it always returns true.

Link to comment
Share on other sites

you could also try this if you don't like all those or case scenarios:

<?php
if(in_array($_GET['ID'], array(18, 9, 13)) { ... }
?>

I am pretty sure the numbers don't need quote since it is in_array should be using == and not === to compare the values but if I am wrong, just check it to the string format.

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.