Jump to content

clear variables when refresh


homer.favenir

Recommended Posts

hi,

i have a php page that submits to itself and insert the the variables to database.

but everytime i refresh the page it inserts again the save variables.

 

how can i clear the variables when i refresh the page?

using a session is not an option because i want it to submit to the same page.

 

TIA

 

 

Link to comment
https://forums.phpfreaks.com/topic/168132-clear-variables-when-refresh/
Share on other sites

it still getting the post variables. :(

<?php
// insert into sec_subject table

$subject = $_POST['subj_check']; // get subject check box
$set = $_POST['sql_trigger']; // get sql trigger

if ($set == $_POST['sql_trigger']) {
		//query
		while (list ($key,$subjName) = @each ($subject)) {
		$exp_subj = explode("|",$subjName);
		$insertSql = "INSERT INTO sec_subject_tbl ( section, subject_code, subject_desc ) values ('$section','$exp_subj[0]', '$exp_subj[1]')";
		echo $insertSql . "<br>";
		}	
$set = NULL;
} //close this if statement
?>

i need to s

Use redirect after the form is submitted and data added succesfully to db.

 

<?php
if (isset($_POST['submit']))
{
    // Do data validation..
    // If ok, add to db.
    header('Location: whateverpage.php');
}

 

i need to submit it to the same page....:(

Thats because you never redirect back to the page you want. Use the header() -function for that like I described earlier. And yes if you want to submit to same page you can just do the redirect to same page. Say your page is form.php where the form is located. You have action in form pointing to this particular page. Then the form processing will be done in form.php this is what you have now right? Then add after you have added data to db the header redirect to the same page also. header('Location: form.php'); And this way the script is not resending the form when refresh is pressed.

to ensure the header() will work, you can put this

 

ob_start(); (very top of the pagE)

 

and use the header to bring back the user to the same page as mentioned above, keeping the user on the page you want.

 

or use AJAX which is probably not something your going to do.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.