【发布时间】:2018-07-22 19:48:35
【问题描述】:
我正在使用 codeigniter 创建一个注册表单。
我已成功完成插入部分,现在我正在尝试使用相同的视图页面更新我的记录,该页面用于将值插入到数据库中。
但是,我遇到了错误:
遇到 PHP 错误 严重性:通知
消息:未定义变量:fn
文件名:views/myform.php
行号:18
谁能帮我解决这个问题?
我无法获取表单中的值。
控制器:
public function updatedata($id)
{
//$id=$this->input->get('id');
$result['data']=$this->Form_model->displayrecordsById($id);
$this->form_validation->set_rules('fname', 'First name', 'required');
$this->form_validation->set_rules('lname', 'Last name', 'required');
$this->form_validation->set_rules('username', 'Username', 'required|min_length[5]|max_length[12]');
$this->form_validation->set_rules('email', 'Email', 'required|valid_email');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('myform',$result);
}
else
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$this->load->library('upload', $config);
$fn=$this->input->post('fname');
$ln=$this->input->post('lname');
$un=$this->input->post('username');
$em=$this->input->post('email');
if($this->upload->do_upload('filename'))
{
$fi= $this->upload->data('file_name');
$file = ("uploads/".$result['data'][0]->filename);
//delete the existing file if needed
if (file_exists($file)) {
unlink($file);
}
}
else
{
$fi= $result['data'][0]->filename;
}
$this->Form_model->updaterecords($fn,$ln,$un,$em,$fi,$id);
echo 'Successfully updated your record';
//exit();
}
}
型号
//get values
function displayrecordsById($id)
{
$query=$this->db->query("select * from form where ID='".$id."'");
return $query->result();
}
//update record
function updaterecords($fn,$ln,$un,$em,$fi,$id)
{
$query=$this->db->query("update form SET first_name='$fn',last_name='$ln',username='$un',email='$em',filename='$fi' where ID='".$id."'");
}
查看
<body>
<?php echo form_open_multipart('form'); ?>
<div class="container">
<h2 style="color:#ff1a1a">Registration Form</h2><br>
<h5 style="color:#ff1a1a">First Name</h5>
<input type="text" class="form-control" name="fname" value="<?php echo set_value("first_name", $fn); ?>" size="50">
<span class="text-danger"><?php echo form_error("fname");?></span>
<h5 style="color:#ff1a1a">Last Name</h5>
<input type="text" class="form-control" name="lname" value="<?php echo set_value("last_name", $ln); ?>" size="50">
<span class="text-danger"><?php echo form_error("lname");?></span>
<h5 style="color:#ff1a1a">Username</h5>
<input type="text" class="form-control" name="username" value="<?php echo set_value("username", $un); ?>" size="50">
<span class="text-danger"><?php echo form_error("username");?></span>
<h5 style="color:#ff1a1a">Email Address</h5>
<input type="text" class="form-control" name="email" value="<?php echo set_value("email", $em); ?>" size="50">
<span class="text-danger"><?php echo form_error("email");?></span>
<h5 style="color:#ff1a1a">Password</h5>
<input type="password" class="form-control" name="password" value="" size="50">
<span class="text-danger"><?php echo form_error("password");?></span>
<h5 style="color:#ff1a1a">Password Confirm</h5>
<input type="password" class="form-control" name="passconf" value="" size="50">
<span class="text-danger"><?php echo form_error("passconf");?></span><br>
<h5 style="color:#ff1a1a">Upload image</h5>
<input type="file" name="filename" size="20">
<img src="<?php echo base_url('uploads/' . $row->filename);?>" class="img-responsive" alt="image" width="100px" height="100px"><br><input type="file" name="filename" value="">
<span class="text-danger"><?php echo form_error("filename");?></span><br>
<div><input type="submit" value="Submit" class="btn btn-success"></div>
</div>
</form>
</body>
【问题讨论】:
标签: php codeigniter