Solved

refresh runs update query

Posted on 2011-09-28
9
300 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 82

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
 
LVL 108

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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 82

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 108

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 108

Expert Comment

by:Ray Paseur
ID: 36737474
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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 transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

757 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now