switch satement fo rsubmit buttons

Discussion in 'PHP' started by fiza23, May 4, 2009.

  1. #1
    i have made a formin which i have three buttons save,delete,update i want to check which button is check by user in a php file how can i do that if any body has idea of it please let me know thnx alot also i want to use switch statement.
     
    fiza23, May 4, 2009 IP
  2. lutics

    lutics Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    switch($_GET['button']) {
    case "save":
    echo "Save Used";
    break;
    case "delete":
    echo "delete Used";
    break;
    case "update":
    echo "Update Used";
    break;
    }

    Depends if you are using Get or Post. Make sure all your buttons have the same name but change the value to , save, delete and update. Should work.
     
    lutics, May 6, 2009 IP
  3. netwaydev

    netwaydev Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    otherwise if you are not willing to use values for whatever reason (you might have multilanguage layout or some other random stuff) you can just do like this:

    if ($_POST['update']) { echo 'update used'; }
    elseif ($_POST['delete']) { echo 'delete used'; }

    your submit buttons would look like

    <input type="submit" value="Whatever you need to be here, update" name="update" />
    <input type="submit" value="Whatever you need to be here, delete" name="delete" />
     
    netwaydev, May 6, 2009 IP
  4. pixmania

    pixmania Peon

    Messages:
    229
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I think @fiza23 wants to log information when a user clicks either of the buttons ?
     
    pixmania, May 6, 2009 IP