我正在学习CodeIgniter,遵循本教程:http://www.tutorialspoint.com/codeigniter/working_with_database.htm 面临以下错误:
遇到PHP错误
严重性:注意
消息:使用未定义的常量roll_no - 假设' roll_no'
文件名:views / Stud_edit.php
行号:16
回溯:
文件:C:\ xampp \ htdocs \ CI \ CI-1 \ application \ views \ Stud_edit.php 行:16 功能:_error_handler
文件:C:\ xampp \ htdocs \ CI \ CI-1 \ application \ controllers \ Stud_controller.php 行:44 功能:查看
文件:C:\ xampp \ htdocs \ CI \ CI-1 \ index.php 行:315 功能:require_once
这里是我的代码" Stud_edit.php"
<!DOCTYPE html>
<html lang = "en">
<head>
<meta charset = "utf-8">
<title>Students Example</title>
</head>
<body>
<form method = "" action = "">
<?php
echo form_open('Stud_controller/update_student');
echo form_hidden('old_roll_no',$old_roll_no);
echo form_label('Roll No.');
echo form_input(array('id'=>'roll_no','name'=>'roll_no','value'=>$records[0]>roll_no));
echo "<br/>";
echo form_label('Name');
echo form_input(array('id'=>'name','name'=>'name','value'=>$records[0]->name));
echo "<br/>";
echo form_submit(array('id'=>'submit','value'=>'Edit'));
echo form_close();
?>
</form>
Stud_controller.php
<?php
class Stud_controller extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->helper('url');
$this->load->database();
}
public function index() {
$query = $this->db->get("stud");
$data['records'] = $query->result();
$this->load->helper('url');
$this->load->view('Stud_view',$data);
}
public function add_student_view() {
$this->load->helper('form');
$this->load->view('Stud_add');
}
public function add_student() {
$this->load->model('Stud_Model');
$data = array(
'roll_no' => $this->input->post('roll_no'),
'name' => $this->input->post('name')
);
$this->Stud_Model->insert($data);
$query = $this->db->get("stud");
$data['records'] = $query->result();
$this->load->view('Stud_view',$data);
}
public function update_student_view() {
$this->load->helper('form');
$roll_no = $this->uri->segment('3');
$query = $this->db->get_where("stud",array("roll_no"=>$roll_no));
$data['records'] = $query->result();
$data['old_roll_no'] = $roll_no;
$this->load->view('Stud_edit',$data);
}
public function update_student(){
$this->load->model('Stud_Model');
$data = array(
'roll_no' => $this->input->post('roll_no'),
'name' => $this->input->post('name')
);
$old_roll_no = $this->input->post('old_roll_no');
$this->Stud_Model->update($data,$old_roll_no);
$query = $this->db->get("stud");
$data['records'] = $query->result();
$this->load->view('Stud_view',$data);
}
public function delete_student() {
$this->load->model('Stud_Model');
$roll_no = $this->uri->segment('3');
$this->Stud_Model->delete($roll_no);
$query = $this->db->get("stud");
$data['records'] = $query->result();
$this->load->view('Stud_view',$data);
}
} ?>
答案 0 :(得分:1)
您的语法有错误..
echo form_input(array('id'=>'roll_no','name'=>'roll_no','value'=>$records[0]>roll_no));
-
中缺少$records[0]>roll_no
..
echo form_input(array('id'=>'roll_no','name'=>'roll_no','value'=>$records[0]->roll_no));