dougaimian1143
2019-03-11 09:52
浏览 65
已采纳

Codeigniter使用相同的表单进行保存和编辑

I am using the same view in CodeIgniter to save and edit. Successfully completed the saving functionality, when using the same form to edit the user. I am getting the error

Message: Undefined variable lastname

<form>
     <input type="text" class="form-control" id="lastname" name="lastname" placeholder="Last name" value="<?php echo $user->lastname; ?>">
</form>
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • douchun5976 2019-03-11 09:53
    已采纳
    <?php
    
    $last_name=NULL;
    if(isset($user->lastname)){
    $last_name=$user->lastname;
    }
    
    ?>
    
    
    <form>
         <input type="text" class="form-control" id="lastname" name="lastname" placeholder="Last name" value="<?php echo $lastname; ?>">
    </form>
    

    I hope this will work

    点赞 打赏 评论
  • dongzanxun2790 2019-03-11 10:20

    Populate the saved value in the view , while fetching from the database. And the while your insert is happening check for same value existed in the db, if value exists in db=>use update else insert

    点赞 打赏 评论

相关推荐 更多相似问题