我在使用以下代码将记录添加到 CodeIgniter 中的“offer”数据库表时遇到问题。
数据库表(mySQL):
1 ID int(11) No
2 OfferName varchar(150) latin1_swedish_ci No
3 OfferLength varchar(150) latin1_swedish_ci No
4 OfferTitle varchar(150) latin1_swedish_ci No
5 OfferDescription varchar(300) latin1_swedish_ci No
6 OfferURL varchar(150) latin1_swedish_ci No
7 OfferContent varchar(300) latin1_swedish_ci No
8 Key varchar(10) latin1_swedish_ci Yes NULL
模型中的方法(offer_model.php):
public function entry_insert(){
$data = array(
'OfferName' => $this->input->post('OfferName'),
'OfferLength' => $this->input->post('OfferLength'),
'OfferTitle' => $this->input->post('OfferTitle'),
'OfferDescription' => $this->input->post('OfferDescription'),
'OfferURL' => $this->input->post('OfferURL'),
'OfferContent' => $this->input->post('OfferContent'),
);
$this->db->insert('offers',$data);
}
控制器:
function addOffer() {
//if the form is submitted
if ($this->input->post('mysubmit')) {
//insert data into db using offer_model model
$this->offer_model->entry_insert();
}
视图中的表格:
<div class="form">
<?php echo form_open('newOffer/addOffer'); ?>
<legend>Please enter details for your new offer</legend>
<label for="OfferName">Offer Name: <span class="required">*</span></label>
<input type="text" name="OfferName" id="Offer Name" placeholder="Please enter the name of your offer"/>
<label for="OfferLength">Offer length:</label>
<input type="text" name="OfferLength" id="OfferLength" placeholder="Please enter the length of your offer"/>
<label for="OfferTitle">Offer title:</label>
<input type="text" name="OfferTitle" id="OfferTitle" placeholder="Please enter the title of your new offer"/>
<label for="OfferDescription">Offer description: </label>
<input type="text" name="OfferDescription" id="OfferDescription" placeholder="Please enter a description of your new offer"/>
<label for="OfferURL">Offer link URL:</label>
<input type="text" name="OfferURL" id="OfferURL" placeholder="Please enter the URL of your new offer"/>
<label for="OfferContent">Offer content:</label>
<input type="text" name="OfferContent" id="OfferContent" placeholder="Please enter the content for your new offer"/>
<fieldset class="submit_field">
<?php echo form_submit('mysubmit', 'Submit Form'); ?>
</fieldset>
</div><!-- end of form div -->
提交表单会导致:
错误号:1054 '字段列表'中的未知列 'OfferName'
只是无法弄清楚,因为表在那里并且字段名称似乎匹配?任何帮助将非常感激。提前致谢!