當我執行編輯表格上驗證它給出了一個錯誤:行無16 未定義的變量score_id,然後對所有變量,它是student_name,SUBJECT_NAME,馬克。編輯形式驗證錯誤
我的控制器文件。
public function edit($id)
{
$this->load->library('form_validation');
$score_id = $this->uri->segment('3');
$this->form_validation->set_rules('std_name','student_name','trim|required|alpha');
$this->form_validation->set_rules('txt_name','subject_name','trim|required|alpha');
$this->form_validation->set_rules('marks','marks','required|numeric');
if ($this->form_validation->run() == FALSE)
{
$score_id = $this->uri->segment('3');
$this->load->view('edit_score');
}
elseif($this->input->post('edit') && $this->input->post('edit_id')!='')
{
$score_id = $this->uri->segment('3');
$data = array(
'score_id' => $this->input->post('score_id'),
'student_name' => $this->input->post('std_name'),
'subject_name' => $this->input->post('txt_name'),
'marks' => $this->input->post('marks'),
);
$result = $this->score->update_record($id,$data);
header('location:'.base_url().'index.php/score_listing');
}
if($id)
{
echo "this is score_id".$id;
$result = $this->score->edit_score($id);
$data['action'] = 'edit';
$data['score_id'] = $result[0]->score_id;
$data['student_name'] = $result[0]->student_name;
$data['subject_name'] = $result[0]->subject_name;
$data['marks'] = $result[0]->marks;
}
echo "welome to edit page";
$this->load->view('edit_score',$data);
}
這是我的編輯文件
<h1>Edit score</h1>
<?php $action = $score_id!='' ? 'edit/'.$score_id : 'add'; ?>
<form name="edit_score" method="post" action="<?php echo $action; ?>">
<input type="hidden" name="score_id" value="<?php echo $score_id;?>"/>
<?php echo form_hidden('admin_id',$this->load->session->userdata('admin_id')); ?>
<!--for above function use form helper in controller file -->
<table style="width:100%" border="0">
<tr>
<td>student Name:</td>
<td><input type="text" name="std_name" value="<?php echo $student_name; ?>"/></td>
<?php echo form_error("std_name"); ?>
</tr>
<tr>
<td>subject Name:</td>
<td><input type="text" name="txt_name" value="<?php echo $subject_name; ?>"/></td>
<?php echo form_error("txt_name"); ?>
</tr>
<tr>
<td>max marks:</td>
<td><input type="text" name="marks" value="<?php echo $marks; ?>" /></td>
<?php echo form_error("marks"); ?>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="edit" value="Submit"/></td>
</tr>
</table>
</form>
我的URI是:http://localhost/ci/index.php/score_listing/edit/1
它提供了以下錯誤: 編輯得分
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: score_id
Filename: views/edit_score.php
Line Number: 16
Backtrace:
File: D:\xampp\htdocs\ci\application\views\edit_score.php Line: 16 Function: _error_handler
File: D:\xampp\htdocs\ci\application\controllers\score_listing.php Line: 64 Function: view
File: D:\xampp\htdocs\ci\index.php Line: 292 Function: require_once
** **行哪一頁的無-16???將您的完整錯誤信息與您的網址一起發佈! – Saty
你的條件不起作用,所以你的score_id變量沒有定義 –
這種方法的郵政編碼$ this-> score-> edit_score($ id); –