Jump to content
MakeWebGames

Question about Switch/Case.


Guest Drizzle

Recommended Posts

Guest Drizzle

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Guest Drizzle
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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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