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?

Received answers to this question:
The best answer according to the author of the question:

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.`