SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    May 2010
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Passing Variables from page to page without forms

    Hi Guys,

    Say you have 2 scripts: index.php which displays a list of items and delete.php which deletes the items (it processes the request only).

    I send the IDs of the items to be deleted from Index.php to delete.php through a form but I want to send those IDs back to index.php so that I can prompt the user that he just deleted those items and present him with an undo possibility.

    How do I get the IDs to index.php back from delete.php?

    The only way I know how to send variables form script to script is through $_post, $_get, which require form submission and $_Session, which I don't think suits the purpose because I'm looking for something more temporary....

    Is there a way? Should I just use $_session?

    I'm not looking for code, just theory.

  2. #2
    SitePoint Evangelist optl's Avatar
    Join Date
    Oct 2004
    Location
    Washington DC
    Posts
    415
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could store them in a session, a database, or pass them via get with a link like:

    Return to index.php?justdeleted=5

    I'd probably be cleanest to create a field in your database user table for recently deleted.
    For the phrase "Bethesda home architect", my clients
    websites occupy 6 of the first 8 results
    on the 1st page of Google. My Secret SEO Strategy Revealed

  3. #3
    SitePoint Member
    Join Date
    May 2010
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I thought about a DB approach but wouldn't that be resource intensive? I already have a flag saying an entry is in the "recycle bin". Once it's deleted, it's out and I don't want to keep a reference to it.

    It's there a simple way to make a variable from script to script that's destroyed as soon as it's used?

  4. #4
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    73 Post(s)
    Tagged
    0 Thread(s)
    How do you pass things to $_SESSION without submission?

    No matter what you do, you're going to have to submit something. PHP does not work in real time. (AJAX submits, just the same as any form)

    You can destroy session variables as easily as you can create them, but you're still going to have to submit them via GET or POST in order to get them into the array, unless you somehow already know what the user wants to do before you present the webpage.

  5. #5
    Barefoot on the Moon! silver trophy Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,615
    Mentioned
    56 Post(s)
    Tagged
    1 Thread(s)
    Easiest way is a $_GET request. Since you don't actually do any processing after this point and just want to display a message, it doesn't really matter if a user changes things in the $_GET request

    page.php?deleted=4

    Code:
    <?php
    $display_deleted_msg = false;
    
    if(isset($_GET['deleted'])){
         if(is_numeric($_GET['deleted']) && $_GET['deleted']>0){
              $id = $_GET['deleted'];
              $display_deleted_msg=true;
         }
    }
    ?>
    <!DOCTYPE html>
    <html>
    <head></head>
    <body>
    <? if($display_deleted_msg===true): ?><div id="delete_msg">Record ID <?php echo $id ?> has been deleted</div><?php endif; ?>
    </body>
    </html>
    And then if you really want to get fancy, fade out the message with JavaScript.
    Visit The Blog | Follow On Twitter
    301tool 1.1.5 - URL redirector & shortener (PHP/MySQL)
    Can be hosted on and utilize your own domain


Bookmarks

Posting Permissions

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