Reputation: 123
I have a form, which on submitted goes to a php file and inserts values into DB(MySql).After successfully inserting values into DB, I want to return back to form screen, with values previously entered and posted. Actually I am using the below code to return back to form page, but am unable to load fields with previous values.
echo "<meta http-equiv='refresh' content='1; URL=form.php'>";
form.php file contains form and add_form.php adds values to database. The above code is written in add_form.php on sql query success
Suggest me an easier way of doing this
Upvotes: 1
Views: 187
Reputation: 5651
In your add_form.php after saving data you can redirect like this.
$url = 'form.php?'.http_build_query($_POST);
header('Refresh:5; url= $url');
And in your form.php you can do this.
<input type="text" name="something" value="<?php echo $_GET['something']; ?>" />
Upvotes: 0
Reputation: 3356
This is how I do it when I need to retain data that is posted via PHP form
if (isset($_POST['your_button_name'])) {
foreach ($_POST as $field => $value)
$this->settings[$field] = $value;
}
and if I need to refer, I simply do $this->settings['field_name']
note: you will ofcourse have to define variable $settings
and make sure to sanitize the data
Upvotes: 0