听到我使用的代码。
$data = array( question=>$this->input->post('questions'),
answer1=>$this->input->post('answer1'),
answer2=>$this->input->post('answer2'),
answer3=>$this->input->post('answer3'),
answer4=>$this->input->post('answer4'),
answer5=>$this->input->post('answer5'),
correctanswer=>$this->input->post('correctanswer')
);
$this->db->insert('questionandanswers',$data);
请为此通知消息提供帮助。
遇到PHP错误
Severity: Notice
Message: Use of undefined constant question - assumed 'question'
答案 0 :(得分:1)
您需要在数组键上添加单引号,因为它将数组键question
视为常量。
你的数组应该像..
$data = array(
'question'=>$this->input->post('questions'),
'answer1'=>$this->input->post('answer1'),
'answer2'=>$this->input->post('answer2'),
'answer3'=>$this->input->post('answer3'),
'answer4'=>$this->input->post('answer4'),
'answer5'=>$this->input->post('answer5'),
'correctanswer'=>$this->input->post('correctanswer')
);
$this->db->insert('questionandanswers',$data);
答案 1 :(得分:0)
在数组索引上放置单引号或双引号,因为数组索引是数字或字符串,而字符串是使用引号定义的。所以改变代码如:
$ data =
array(
'question'=>$this->input->post('questions'),
'answer1'=>$this->input->post('answer1'),
'answer2'=>$this->input->post('answer2'),
'answer3'=>$this->input->post('answer3'),
'answer4'=>$this->input->post('answer4'),
'answer5'=>$this->input->post('answer5'),
'correctanswer'=>$this->input->post('correctanswer'));
$this->db->insert('questionandanswers',$data);
答案 2 :(得分:0)
必须引用数组字符串键。在您的数组'问题',' answer1'必须引用。例如'question'=>$this->input->post('questions')
答案 3 :(得分:0)
需要所有数组key
单引号或双引号,如下:
$data = array(
"question"=>$this->input->post('questions'),
"answer1"=>$this->input->post('answer1'),
"answer2"=>$this->input->post('answer2'),
"answer3"=>$this->input->post('answer3'),
"answer4"=>$this->input->post('answer4'),
"answer5"=>$this->input->post('answer5'),
"correctanswer"=>$this->input->post('correctanswer')
);
答案 4 :(得分:0)
$data = array(question=>$this->input->post('questions'),answer1=>$this->input->post('answer1'),answer2=>$this->input->post('answer2'),answer3=>$this->input->post('answer3'),answer4=>$this->input->post('answer4'),answer5=>$this->input->post('answer5'),correctanswer=>$this->input->post('correctanswer'));$this->db->insert('questionandanswers',$data);
这里有什么问题你需要将问题和其他索引用作字符串,如
array('question' => $this->input->post('questions'))
答案 5 :(得分:0)
您缺少数组语法
$data = array( 'question'=>$this->input->post('questions'),
'answer1'=>$this->input->post('answer1'),
'answer2'=>$this->input->post('answer2'),
'answer3'=>$this->input->post('answer3'),
'answer4'=>$this->input->post('answer4'),
'answer5'=>$this->input->post('answer5'),
'correctanswer'=>$this->input->post('correctanswer'));
$this->db->insert('questionandanswers',$data);