Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Using $_GET

  1. #1
    Regular Coder
    Join Date
    Jan 2007
    Posts
    217
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Using $_GET

    Hey,

    I want to use the $_GET function more in order to help decrease the number of pages i have on my server.

    Basically, i have a function which deletes an item called deleteitem.php, which is display on items.php

    What i want to do is, say have items.php?action=deleteitem&&id=$itemid .

    But where and how would i write the deleteitem program. Like, i could just grab the variables from the URL and then do the program, but how will the program know when to act? If you don't understand what i'm getting at, sorry!

    like, first part of items.php would be:

    Display Item
    Delete Item

    What if the user visits item.php and doesn't want to delete the item but the code is already on items.php and so how do i stop that from happening?

    Any help at all would be appriciative!

    Thanks.

  • #2
    Regular Coder
    Join Date
    Oct 2005
    Location
    Right Here
    Posts
    654
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Yea sure I understand, check it out:

    In your items.php page set it up like so.
    PHP Code:
    if(isset($_GET['action'])) {
        
    $action $_GET['action'];
    }else{
        
    $action $default_action;
    }

    //then put in code for delete
    if($action == "deleteitem" && isset($_GET['id']) && ...) {
    //is_num && isnt blank, and w/e other checks you want, maybe verify id existes?
        
    $delete_query "delete from items where id = $id;
    } else 
    if($action == "
    home")
    //show this... etc

    Make sense?

  • #3
    Regular Coder
    Join Date
    Jan 2007
    Posts
    217
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Yes i think so! *goes to try* thank you!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •