I'm teaching myself PHP from tutorials, and am trying to save some object properties to a php file, as persistant data, so I can later retrieve them in another user session. (Yesi, I know how to save to a database, but for this simple case I want to learn how to save &retrieve from a webform, writing it to another php file.) I'd like the form pre-populated with whatever the value of the data object’s property was when last saved. My code so far:
<?php require "objects.php"; ?>
$firstname = $id1->firstname
<form name="EditObject" method="post" action="objects.php" >
<input type="text" name="firstname" id="firstname" value = "<?php echo $firstname; ?> ">
<br>
<input type="submit" name="submit" value="Submit">
</form>
AND the objects.php file:
class Users { public $firstname = ''; }
$id1 = new Users();
if ( isset( $_POST['submit'] ) ) {
$firstname = $_REQUEST['firstname'];
$id1->firstname = $firstname;
echo 'data updated'; echo '<br>';
echo $id1->firstname; echo '<br>';
}