Reputation: 2925
I've made a normal HTML form which when submitted, sends information to another page and that page processes the data and adds it to the database. But for some reason, if I refresh the 1st page which contains the form, an entry is being made into the database even though I can't see any reason for it to do so.
This is the code for the form:
<?php $owner = $_GET['user']; ?>
<h2 class="dotted"><?php _e('Add feedback for user','appthemes'); echo " - ".$owner;?></h2>
<form id='feedback' action='http://www.example.co.uk/add-feedback-response/?user=<?php echo $owner; ?>' method='POST' accept-charset='UTF-8'>
<fieldset >
<b>Your Username:</b> <?php echo $current_user->user_login; ?><br/><br/>
<b>Rating: </b>
<input type="radio" name="rating" value="positive" /> Positive
<input type="radio" name="rating" value="neutral" /> Neutral
<input type="radio" name="rating" value="negative" /> Negative<br/><br/>
<label for='item' ><b>Item bought:</b></label>
<input type="text" name='item' id='item' maxlength="500"/><br/><br/>
<label for='comment' ><b>Comment:</b></label>
<textarea name='comment' id='comment' maxlength="2500"></textarea><br/><br/>
<input type="submit" id="submit-button" value="Submit Feedback" />
</fieldset>
</form>
Is there something I'm missing? Thanks for any help
Upvotes: 0
Views: 55
Reputation: 18344
If you refresh the form after it has submitted once, the form will be submitted again. (the browser would have warned you, "Are you sure you want to submit the page again" - didn't it?) Refresh is actually "repeat the last request".
If you think such a scenario is possible in your webapp, you will have to handle duplicate requests.
Upvotes: 0
Reputation: 50966
It is probably because you're trying to submit form again. Is browser alerting you that you're sending data again?
to restrict this, use
header("Location: ".$_SERVER['HTTP_REFERER']);
in proccessing form
Upvotes: 1