Jump to content
MakeWebGames

Question about Switch/Case.


Recommended Posts

Guest Drizzle
Posted

For some reason, no matter what i do, if $_GET['cmd'] in the url = Delete, which is suppose to delete something, voids the function. However changing delete to delet,remove,del, etc. works fine. Anyone have any info on this?

Guest Drizzle
Posted
  switch($_GET['cmd']){
    case 'Add': cmd_add(); break;
    case 'Edit': cmd_edit(); break;
    case 'Delete': cmd_delete(); break;
}

       function cmd_add(){
         //code
      }

      function cmd_edit(){
        //code
      }

      function cmd_delete(){ 
         //code
     }

 

along the lines of that. I've done that format with the code and everything, and when the case = delete, it decides not to execute the delete switch. However, if its delet, del, remove, rm, etc. it works fine. I've checked for any problems that may have caused it. The code is fine, and it makes no sense that it isnt working. Also i do secure my code, but this is just a small example of what im trying to do, and i'm not going to worry about writing that down here.

Posted

it could be that delete is a sort of "function" itself.

I encountered the same problem but trying to use

do

im assuming it won't work for any words such as

do, for, if, etc.

Though im not positive as i don't know if delete is a "function" itself like do, or for.

Posted

if the function defined before hand?

for example i can't use the function index in a sub file

index.php?page=index&cmd=index

(i might be wrong lol i just seem to remember having a issue with index).

So if your using sub files like i do on CrimGame.com so index (in the page GET super global) is linked from like /modifications/files/index_page.php

and the cmd=index is in there then that would be your issue.

of if you define delete in some global file or header that could also be it.

Considering delete() is shown as a function but actually isn't i wouldn't be worried about that.

Guest Drizzle
Posted
if the function defined before hand?

for example i can't use the function index in a sub file

index.php?page=index&cmd=index

(i might be wrong lol i just seem to remember having a issue with index).

So if your using sub files like i do on CrimGame.com so index (in the page GET super global) is linked from like /modifications/files/index_page.php

and the cmd=index is in there then that would be your issue.

of if you define delete in some global file or header that could also be it.

Considering delete() is shown as a function but actually isn't i wouldn't be worried about that.

Nope it isnt using a sub. Just plain switch/case. and the function is defined

Posted

Some technical data that may count.;

Defining a string a literal 'string', may cause a problem with the case the word is defined as(CAPS or not).

Try low-case names, it might just help.

Posted

If statements for the simplest.

Another way, yet I don't want to admit that programmers use is also below;

 

// if statement
if ($foo == 'bar') fooFTW();

// "other" method
$bar = array('blah', 'bleh', 'gah');
$getVar = (key_exists($foo, $bar)) ? $foo : null;
$getVar(); // messy.. very
Posted
If statements for the simplest.

Another way, yet I don't want to admit that programmers use is also below;

 

// if statement
if ($foo == 'bar') fooFTW();

// "other" method
$bar = array('blah', 'bleh', 'gah');
$getVar = (key_exists($foo, $bar)) ? $foo : null;
$getVar(); // messy.. very

Yeah..

BTW key_exists() is no php function. :) - array_key_exists()/in_array(), use what ever.

Posted

He has nothing to say now, aww! IDIOT, YOU LIKE MY SIGNATURE ON MY PROFILE? :D

Posted

LOL - Hes just being a idiot deleting every post, i can post faster than you deleting them. :D

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.   Paste as plain text instead

  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...