What I would do is after the INSERT query is executed, redirect the user back to index.php. To do this, use the following code:

// run mysql queries here
mysql_query('INSERT ...', $conn);

// after running, redirect to index.php
header('Location: index.php');
exit;

This will cause the browser to redirect to index.php. This is compatible with all browsers as it is a HTTP standard.

Hope that helps,

-Percy

    Originally posted by GreyBoy
    I think this would work:

    $page = 'index2.php';
    if($_SERVER['REQUEST_URI'] == $page)
    {
        $i = 1;
    }
    
    if(!isset($i))
    {
           // MySQL Stuff Here
    }
    

    or maybe just:

    $page = 'index2.php';
    if($_SERVER['REQUEST_URI'] != $page)
    {
        // MySQL Stuff Here
    }
    

    [/B]

    The problem is that $_SERVER['REQUEST_URI'] contains always '/index2.php'.....if i go from index2.php to index3.php and also if i make a refresh on page index3.php.
    So it always do the MYSQL stuff........
    What's wrong?

      Try using the header() function as I described above, I'm pretty sure that's what you want it to do, as I've done similar things before.

      -Percy

        Originally posted by m@tt
        You could possibly set a cookie but it's the browser that does this, not the script. When you send POST headers through the browser and then hit refresh, the browser will attempt to re-send those POST headers.

        You could do a check against the database to see if it has already been entered, but the headers will still be sent regardless.

        Matt sorry but you are in wrong.....if i have understood.....
        if you put a $sess_variable=1 in index2.php and then in the start of index3.php you check if this variable is ==1 and the do the mysql stuff then set this variable to "" for example on the refresh done in index3.php it will do nothing!

        index2.php
        sesion_start();
        $sess_v=1;
        session_register(sess_v);

        index3.php

        session_start()
        if ($sess_v==1)
        {
        //MYSQL STUFF
        $sess_v="";
        session_unregsiter(sess_v);
        }
        else
        {
        header("Location: index.php");
        exit();
        }

        And that's all for avoid refresh on index3.php but i have to use session!

          Originally posted by majiclab
          Try using the header() function as I described above, I'm pretty sure that's what you want it to do, as I've done similar things before.

          -Percy

          Well.....i have to show some variables passed from index2.php so i can't redirect immidiatly on page index.php.....only if you make a refresh on index3.php.

            Oh sorry, I did not know that you were printing the info back on index3.php.

            In that case the session variable should work fine! 🙂

            -Percy

              Anyone could replay me and help me?
              No one know how to do this thing without the session?

              no one?

                Well......could someone suggest me something else to do this thing without session?

                  The only way to do it without sessions would be to have it go to another page after it is inserted.

                  -Percy

                    Write a Reply...