Categories: javascript, php, html, session

HTML form doesn't reset after page refresh

2 answers

I complete the following HTML form in my "main" page(main.php):

<form action="sessions.php" method="post">   <input type="" placeholder="Insert Database Name" name="dbName" id="dbName">   <input type="" placeholder="Insert Server Name" name="serverName" id="serverName">   <input type="" placeholder="Insert User Name" name="userName" id="userName">    <button type="submit" name="Submit" id="sub">Connect</button> </form> 

When the user presses the "Submit" button(I made it to not refresh the page), the form data are posted to another page(sessions.php):

<?php   session_start();    $_SESSION['dbName'] = $_POST['dbName'];   $_SESSION['serverName'] = $_POST['serverName'];   $_SESSION['userName'] = $_POST['userName'];   $_SESSION['password'] = $_POST['password']; ?> 

Then, those data are read from another page(graphs.php):

<?php    session_start();    $serverName = $_SESSION['serverName'];   $userName = $_SESSION['userName'];   $password = $_SESSION['password'];   $dbName = $_SESSION['dbName']; ?> 

When I refresh the page, the form data are preserved. How to delete them after page refresh?

All answers to this question, which has the identifier 61237016

The best answer:

Use session_destroy() after you have handled the data (stored in database, performed calculation etc.) HTTP is a stateless protocol, so refreshing the page would not update your session variables because it is the PHP server that is handling the session, completly unrelated to a page refresh.

`Hey Try this with the function method above input methods.. create a simple function using onclick method in the submit button and put the values=null in side the function eg.

"function clearForm() {    document.myform.reset();                    }" 

But the session_destroy(); for deleting the whole session. And

"session_unset(); would delete only the variables from session - session still exists. Here Only data is truncated."

They both are better option.`

Last questions

how do i remove the switch on my home screen?
how to edit the JS date and time to update atuomatically?
How to utilize data stored in a multidimensional array
Powermockito not mocking URL constructor in URI.toURL() method
Android Bluetooth LE Scanner only scans when phone's Location is turned on in some devices
docker wordpress container can't connect to mysql container
How can I declare a number in java that is more than 64-bits? [duplicate]
Optaplanner solutionClass entityCollectionProperty should never return null error when simple JSON object passed to controller
Anylogic, get the time a pedestrain is in a queue
How do I fix this syntax issue with my .flex file?
Optimizing query in PHP
How to find the highest number of a column and print two columns of that row in R?
Ideas on “Error: Type com.google.firebase.iid.zzav is referenced as an interface from com.google.firebase.messaging.zzd”?
JCIFS SmbFile.exists() and SmbFile.isDirectory() return false when it exists and I can listFiles()
PHP total order
Laravel booking system design
neural net - undefined column selected
How to indicate y axis does not start from 0 in ggplot?
Fragments in backStack
Spinner how to change the data