user3549665
user3549665

Reputation: 123

Keeping form values after POST

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

Answers (3)

Jay Bhatt
Jay Bhatt

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

oohcode
oohcode

Reputation: 429

you can try JavaScript ajax to do this~

Upvotes: -1

Shairyar
Shairyar

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

Related Questions