Question

i an new to php . please help me how to remember text input in PHP forms after go back to form ?

i have an rgister page and want to save text input in database , but if a text input existing in database go back to register page but remember text input . please help me !

Was it helpful?

Solution 2

Use PHP session

<?php 
session_start(); 
$_SESSION['name'] = "YourSession"; 
// ...
?>

OTHER TIPS

Save the data in your session.

Call

session_start();

in the form.php and your target.php. In target.php parse all your $_POST/$_GET Parameters and store them in the session.

$_SESSION['user_name'] = check_for_valid_name($_POST['user_name']);

in form.php just set input default to your session Variable:

<input name='user_name' value='<?= $_SESSION['user_name'] ?>' />

edit: In form.php you can also use:

value='<?php isset($_SESSION['user_name'])?(echo $_SESSION['user_name']):(echo "") ?>'

to get rid of warnings/notices of uknown index/variable.

You can store the details in a session variable. You'll have to learn working with sessions though.

define your input field something like this.this will retain values after submission

 <input id="user_firstname" type="text" name="user_firstname" value=<?= $_POST['user_firstmane'] ?> >
<form action="action.php" method="post">
<input type="text" name="inmputname" value="<?php echo $_POST['inmputname']?>">
<input type="submit">
</form>

Hope it will help you

Just try this one,

<?php
$name = NULL;
if(isset($_POST['submit'])){
$name=$_POST['inputname'];
}
?>

And in your form,

<form action="action.php" method="post">
<input type="text" name="inputname" value="<?php echo $name;?>">
<input type="submit">
</form>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top