<html>
<body>
<form method="post">
Name :<input type = "text" name= "name" value = "<?php echo $_GET["name"];?>">
salary :<input type = "number" name = "salary" value = "<?php echo $_GET["salary"]?>">
<input type = "submit" value = "submit">
</form>
</body>
</html>
In the above code, name and salary text box fetches the value from url. And once we change name or salary text box value, and if we submit the form the "post" method will be called and the name salary values will be stored in the table.
Now my query is once the form is submitted, I want new values of name and salary to be displayed in respective text boxes,and in similar way how can I achieve that in select box, radio box and check boxes.
Two ways:
change the method to get
: <form method="get">
change the values you echo to:
<?php echo isset($_POST["name"])?$_POST["name"]:$_GET["name"];?>
For select:
<select name = "department">
<?php $output = $connection->get_department();
if($output["status"] == 1){
$array = $output["array"];
foreach($array as $res){?>
<option value = "<?php echo $res["id"];?>">
<?php echo $res["name"];
if(isset($_POST["name"]) && $_POST["name"] == $res["name"]){
echo " selected";
}?>
</option>
<?php
}
}
?>
</select>