Jump to content

Preventing data being inserted into database again on refresh?


zq29

Recommended Posts

I have a script where I allow a user to add, edit or delete information from a database. I normally have three seperate sets of pages for each function, i.e. the form on one page, and the processing on another. In an attempt to make things cleaner I am integrating all of the scripts into one. My only problem is, if a user should decide to click refresh (for what ever reason) after perviously adding some info to the database, the info is added again, and again on any further refresh. Does anyone know of a method to prevent this, maybe by clearing the variables from the browser cache or something? - I don't know how this works technically at a browser level...

Heres a demo script to give you an idea of the kinda script I have:
[code]<?php
if(isset($_POST['submit'])) {
    mysql_query("INSERT INTO `table` (`name`) VALUES ('$_POST[name]')");
}
?>
<form name="add" action="" method="post">
    <input type="text" name="name"/>
    <input type="submit" name="submit" value="Insert"/>
</form>[/code]
Link to comment
Share on other sites

Something along the lines of...



// Get the last row from the table before entering the new one.
SELECT * FROM table ORDER BY (unique id number field) DESC LIMIT 1

// Compare the content with the variables you've just submitted
if($db_variable=="$_POST[variable]")
{
// dont enter into the database
}
else
{
// DO ENTER into the database
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.