On this task, How to Keep Value After Page Reload in PHP, 2 major things we have to know about,
- PHP Session
- Inline If Else Condition

In This Article
Use of PHP Session and Inline If Else Condition
We use both PHP sessions to store the posted data from the form, then we check the value using inline if else condition on the textbox value.
Example: How to Keep Value After Page Reload in PHP
1 2 3 4 5 6 7 8 9 10 |
<?php session_start(); if (isset($_POST['submit'])) { $_SESSION['test'] = $_POST['test']; } ?> <form method="post" action=""> <input type="text" value="<?php echo isset($_SESSION['test']) ? $_SESSION['test'] : ''; ?>" name="test" /> <input type="submit" value="submit" name="submit" /> </form> |
Code Explanations:
- Create an HTML form with one textbox and submit button.
- On the same textbox, we check any input value is available or not using PHP
isset()
function and inline If Else condition. - 3 things are used on the textbox,
- First is PHP
isset()
function. - inline If Else condition
- And session for, get the stored value after a click.
- First is PHP
- After clicking on the submit button we store the posted data to the PHP session.
You can read more about the session on the official website, https://www.php.net/manual/en/book.session.php
How To Run:
PHP Online Editor: https://phpcoder.tech/php-online-editor/
Open the above link and paste the complete code to check. If not worked because of the URL you can use your own localhost.
Also Read:
- Login with Google Account using PHP Step by Step
- PHP Superglobal Variables
- CSS background-image Properties
- Best User Login Page Design Using Neumorphism
- CSS Background Image Text Effect
Happy Coding..!
Was this article helpful?
YesNo
Pingback: Export MySQL Data to Excel in PHP Using Ajax - PHPCODER.TECH
Pingback: How to Encrypt and Decrypt Image Path in PHP - PHPCODER.TECH
Pingback: How to Convert Number to Words in PHP Ajax - PHPCODER.TECH
Pingback: Check If Folder Or File Exists Using JavaScript - PHPCODER.TECH
Pingback: Get Selected Date From Calendar in PHP using Ajax - PHPCODER.TECH
Pingback: Migrate WordPress Site To New Host Manually - PHPCODER.TECH
Pingback: Detect URL Change in JavaScript Without Refresh - PHPCODER.TECH
Pingback: Allow Only String and Numbers Using PHP - PHPCODER.TECH
Pingback: Set-up Firebase Project using Firebase Console - PHPCODER.TECH
Pingback: How to Open an External URL in PHP - PHPCODER.TECH