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

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>

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

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