0

我正在从教程中自学 PHP,并尝试将一些对象属性作为持久数据保存到 php 文件中,以便以后可以在另一个用户会话中检索它们。(是的,我知道如何保存到数据库,但对于这个简单的案例,我想学习如何从 web 表单中保存 &retrieve,将其写入另一个 php 文件。)我希望表单预先填充任何值数据对象的属性是上次保存的时间。到目前为止我的代码:

<?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>

和 objects.php 文件:

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>';
}
4

0 回答 0