我试图将表单提交给控制器,然后将其插入到数据库中。它工作了几天,但显然我不小心改变了一些东西,因为它“随机”不起作用。任何帮助将不胜感激,因为我在网上搜索后无法弄明白。谢谢!
PHP
public function houses () {
if ($this->input->post()) {
$bedrooms = $this->input->post('bedrooms');
$bathrooms = $this->input->post('bathrooms');
$street = $this->input->post('street');
$house_number = $this->input->post('house_number');
$basement = $this->input->post('basement');
$garage = $this->input->post('garage');
$fence = $this->input->post('fence');
$query = $this->db->query('INSERT INTO houses VALUES (NULL, "'.
$bedrooms.'","'.$bathrooms.'","'.$house_number.'","'.
$street.'","'.$basement.'","'.$garage.'","'.$fence.'")');
}
$query = $this->db->query("SELECT * FROM houses");
foreach($query->result() as $row) {
$data['bedrooms'] = $row->bedrooms; $data['bathrooms'] = $row->bathrooms;
$data['house_number'] = $row->house_number;
$data['street'] = $row->street; $data['garage'] = $row->garage;
$data['basement'] = $row->basement; $data['fence'] = $row->fence;
$data['id'] = $row->id;
$this->data['houses'][] = $data;
}
$title = 'Houses';
$this->data['title'] = $title;
$this->template->add_css('css/dog.css');
$this->template->write_view('content', 'houses', $this->data);
$this->template->render();
}
HTML
<form method='post' action='<?php site_url('welcome/houses')?>'>
<li><span>Bedrooms</span>
<input type="text" name="be stdClass::$emaildrooms" /></li>
<li><span>Bathrooms</span>
<input type="text" name="bathrooms" /></li>
<li><span>House Number</span>
<input type="text" name="house_number" /></li>
<li><span>Street</span>
<input type="text" name="street" /></li>
<li>
<span>Basement</span>
<select name="basement">
<option>Yes</option>
<option>No</option>
</select><br/>
</li>
<li>
<span>Garage</span>
<select name="garage">
<option>Yes</option>
<option>No</option>
</select><br/>
</li>
<li>
<span>Fence</span>
<select name="fence">
<option>Yes</option>
<option>No</option>
</select><br/>
</li>
<input type="submit" name="Submit" />
</form>
答案 0 :(得分:0)
您的错误在这里:
<input type="text" name="be stdClass::$emaildrooms" />
be stdClass::$emaildrooms
包含Codeigniter在输入键中不允许的字符。
反正看起来像是一个错误,好像stdClass::$email
以某种方式偷偷摸摸 - 可能是你在文件中进行了大量的搜索/替换。