?
Solved

refresh runs update query

Posted on 2011-09-28
9
Medium Priority
?
309 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 84

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 111

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 84

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 111

Accepted Solution

by:
Ray Paseur earned 2000 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 111

Expert Comment

by:Ray Paseur
ID: 36737474
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

650 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