Solved

refresh runs update query

Posted on 2011-09-28
9
302 Views
Last Modified: 2012-05-12
how do i clear the refresh cache or the last process from being ran again?

say for instance:

i type a comment on a picture i click refresh and it wants to send comment again. how do i get it to where it doesnt want to send again it will just refresh the page and not the update query.

do i clear the cache and then require it to refresh it self or what?

thanks in advance for your help!
0
Comment
Question by:only1wizard
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 25

Expert Comment

by:Kyle Hamilton
ID: 36720030
The code?
A link?

we're not psychic :)
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 36720087
That is normal operation for Refresh.  If you want it to do something else, you need it to go to a page that was Not loaded with a POST or form submission.  Click on another link.  ??
0
 
LVL 82

Expert Comment

by:leakim971
ID: 36720089
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 109

Expert Comment

by:Ray Paseur
ID: 36720172
The best answer I have found is to write your code in such a way that the refresh does not adversely affect the data model.  Refresh happens.  
0
 

Author Comment

by:only1wizard
ID: 36720566
hello -

thanks for the quick response this is what i have:

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form2")) {

// do database insert

}

Open in new window


<form action="<?php echo $editFormAction; ?>" method="post" name="form2" id="form2">
      <table align="left">
        <tr valign="baseline">
          <td nowrap="nowrap" align="left">catagory:</td>
          <td><select name="catagory">
            <?php
do {  
?>
            <option value="<?php echo $row_cat['Id']?>"><?php echo $row_cat['catagory']?></option>
            <?php
} while ($row_cat = mysql_fetch_assoc($catagory));
  $rows = mysql_num_rows($catagory);
  if($rows > 0) {
      mysql_data_seek($catagory, 0);
	  $row_cat = mysql_fetch_assoc($catagory);
  }
?>
          </select>
</td>
        </tr>
        <tr valign="baseline">
        	<td nowrap="nowrap" align="left">feelings </td>
            <td><textarea name="feelings" cols="32" rows="3" ></textarea></td>
        <tr valign="baseline">
          <td nowrap="nowrap" align="right">&nbsp;</td>
          <td><input type="submit" value="Submit" /></td>
        </tr>
      </table>
      <input type="hidden" name="MM_insert" value="form2" />
    </form>

Open in new window


can i do an unset($_Post)? after it has completed its database inserts with out errors?

0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 36720734
You can do that but it has no effect on the Refresh because the Refresh page load is done in the browser.  Clicking on submit POSTs data from the form to an 'action' page.  If you Refresh the 'action' page, the browser will send the data gain because that is how it got to that page.  That is how it is supposed to work.
0
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 36727384
For better or worse, computer programming requires precision.  The PHP statement unset($_Post) will have no effect at all because PHP variable names are case-sensitive.  You would want unset($_POST).  And that would not work, either because the refresh would send a new POST array.

Here is how you can prevent repeated requests.  Please read it over carefully and post back with any questions.

Best of luck with it, ~Ray
<?php // RAY_multi_submit.php
error_reporting(E_ALL);


// PREVENT MULTIPLE SUBMISSIONS DUE TO REPEATED REFRESH, CLICKS ON SUBMIT BUTTON OR FIRING THE BACK BUTTON
// EXAMPLE:
//    if ( multi_submit() )
//    {
//       handle error
//    }
//    else
//    {
//       normal processing
//    }


// ALWAYS START THE PHP SESSION ON EVERY PAGE
session_start();



// A FUNCTION TO RETURN TRUE OR FALSE ABOUT MULTI-SUBMIT CONDITIONS
function multi_submit($type="POST")
{
    // MAKE THE FUNCTION WORK FOR EITHER GET OR POST SUBMITS
    $input_array = (strtoupper($type) == "GET") ? $_GET : $_POST;

    // GATHER THE CONTENTS OF ALL THE SUBMITTED FIELDS AND MAKE A MESSAGE DIGEST
    $string = NULL;
    foreach ($input_array as $val)
    {
        // CONCATENATE ALL SUBMITTED VALUES
        $string .= $val;
    }
    $string = md5($string);

    // IF THE SESSION VARIABLE IS NOT SET THIS IS NOT A MULTI-SUBMIT
    if (!isset($_SESSION["_multi_submit"]))
    {
        // SAVE THE SUBMITTED DATA MESSAGE DIGEST
        $_SESSION['_multi_submit'] = $string;
        return FALSE;
    }

    // IF THE SESSION DATA MATCHES THE MESSAGE DIGEST THIS IS A MULTI-SUBMIT
    if ($_SESSION['_multi_submit'] === $string)
    {
        return TRUE;
    }
    else
    {
        // SAVE THE MESSAGE DIGEST TO DETECT FUTURE MULTI-SUBMIT
        $_SESSION['_multi_submit'] = $string;
        return FALSE;
    }
}



// SHOW HOW THIS IS DONE
if (!empty($_POST))
{
    if (multi_submit())
    {
        die("ALREADY GOT THAT");
    }
}



// CREATE THE FORM FOR THE DEMONSTRATION
$form = <<<FORM
<form method="post">
ENTER SOMETHING, THEN REENTER IT
<input name="foo" />
<input type="submit">
</form>
FORM;

echo $form;

Open in new window

0
 

Author Comment

by:only1wizard
ID: 36732805
thanks for the example  i will give this a try and post results!
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 36737474
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

822 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question