Note that there are some explanatory texts on larger screens.

plurals
  1. POPreventing a submission from being re-submitted upon refreshing a browser
    primarykey
    data
    text
    <p>The code below all works great. On a file called submit.php, a user can enter a submission through a form. The form goes to submit2.php, where some code inserts the submission into a MySQL database. So far so good.</p> <p>Here's the problem: once the user has landed on submit2.php, if the user refreshes the browser, a "Confirm Form Resubmission" pop-up box appears. Then, if the user hits "Continue" on that pop-up, the submission will be re-submitted to the MySQL database.</p> <p>How can make it do the following on submit2.php:</p> <ol> <li><p>The pop-up will not appear if the browser is refreshed.</p></li> <li><p>The submission will not be re-submitted to the database. </p></li> </ol> <p>Thanks in advance,</p> <p>John</p> <p>On submit.php:</p> <pre><code>echo '&lt;form action="http://www.domain.com/sample/submit2.php" method="post"&gt; &lt;input type="hidden" value="'.$_SESSION['loginid'].'" name="uid"&gt; &lt;div class="submissiontitle"&gt;&lt;label for="title"&gt;Story Title:&lt;/label&gt;&lt;/div&gt; &lt;div class="submissionfield"&gt;&lt;input name="title" type="title" id="title" maxlength="1000"&gt;&lt;/div&gt; &lt;div class="urltitle"&gt;&lt;label for="url"&gt;Link:&lt;/label&gt;&lt;/div&gt; &lt;div class="urlfield"&gt;&lt;input name="url" type="text" id="url" maxlength="500"&gt;&lt;/div&gt; &lt;div class="submissionbutton"&gt;&lt;input name="submit" type="submit" value="Submit"&gt;&lt;/div&gt; &lt;/form&gt; '; </code></pre> <p>On submit2.php:</p> <pre><code>if (isLoggedIn() == true) { $remove_array = array('http://www.', 'http://', 'https://', 'https://www.', 'www.'); $cleanurl = str_replace($remove_array, "", $_POST['url']); $cleanurl = strtolower($cleanurl); $cleanurl = preg_replace('/\/$/','',$cleanurl); $cleanurl = stripslashes($cleanurl); $title = $_POST['title']; $uid = $_POST['uid']; $title = mysql_real_escape_string($title); $title = stripslashes($title); $slug = str_replace(' ', '-', $title); echo '-'.$site1.'-'; $cleanurl = mysql_real_escape_string(trim($cleanurl)); $site1 = 'http://' . $cleanurl; $displayurl = parse_url($site1, PHP_URL_HOST); function isURL($url1 = NULL) { if($url1==NULL) return false; $protocol = '(http://|https://)'; $allowed = '[-a-z0-9]{1,63}'; $regex = "^". $protocol . // must include the protocol '(' . $allowed . '\.)'. // 1 or several sub domains with a max of 63 chars '[a-z]' . '{2,6}'; // followed by a TLD if(eregi($regex, $url1)==true) return true; else return false; } if(isURL($site1)==true) mysql_query("INSERT INTO submission VALUES (NULL, '$uid', '$title', '$slug', '$cleanurl', '$displayurl', NULL)"); else echo "&lt;p class=\"topicu\"&gt;Not a valid URL.&lt;/p&gt;\n"; } else { // user is not loggedin show_loginform(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload