Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 312
  • Last Modified:

refresh runs update query

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
only1wizard
Asked:
only1wizard
  • 3
  • 2
  • 2
  • +2
1 Solution
 
Kyle HamiltonData ScientistCommented:
The code?
A link?

we're not psychic :)
0
 
Dave BaldwinFixer of ProblemsCommented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Ray PaseurCommented:
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
 
only1wizardAuthor Commented:
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
 
Dave BaldwinFixer of ProblemsCommented:
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
 
Ray PaseurCommented:
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
 
only1wizardAuthor Commented:
thanks for the example  i will give this a try and post results!
0
 
Ray PaseurCommented:
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now