- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试将一些表单数据插入到 codeigniter 中的 mysql 表中。我的问题是,在插入实际数据之前,表格中插入了一个空白行。然后我发现,即使页面加载或刷新时,也会将空白行插入到 mysql 中。
这是我的代码:
Controller :
class Amc extends MX_Controller {
function __construct()
{
parent::__construct();
// check if user logged in
if (!$this->ion_auth->logged_in())
{
redirect('module=auth&view=login');
}
$this->load->library('form_validation');
$this->load->model('amc_model');
}
function addamc()
{
$data = array('cust_id' => $this->input->post('customer_id'),
'cust_name' => $this->input->post('cname'),
'cust_address' => $this->input->post('addr'),
'contact_person' => $this->input->post('contact_prsn'),
'location' => $this->input->post('loc'),
'email' => $this->input->post('email'),
'prs' => $this->input->post('prs'),
'rating' => $this->input->post('rating'),
'hrs' => $this->input->post('hrs'),
'engine_num' => $this->input->post('engine'),
'model' => $this->input->post('model'),
'amc_from' => $this->input->post('amcfrom'),
'amc_to' => $this->input->post('amcto'),
'expiry_date' => $this->input->post('expd'),
'no_visit_agreed' => $this->input->post('visagree'),
'no_visit_made' => $this->input->post('vismade'),
'date_commence' => $this->input->post('doc'),
'last_oil_ser_date' => $this->input->post('losd'),
'last_visit_date' => $this->input->post('lvd'),
'visit_due' => $this->input->post('visitdue'),
'visit_status' => $this->input->post('visitstatus'),
'svc_status' => $this->input->post('svcstatus'),
'amc_status' => $this->input->post('amcstat'),
'actual_amt' => $this->input->post('actualamt'),
'amt_recieved' => $this->input->post('amtrecieved'),
'amt_due' => $this->input->post('amountdue'),
'payment_method' => $this->input->post('paymentmethod'),
'payment_due_date' => $this->input->post('paymentdue'),
'assigned_to' => 'not assigned'
);
$this->amc_model->addamc($data);
if ( $this->form_validation->run() == true &&$this->amc_model->addamc($data) )
{
$this->session->set_flashdata('success_message', $this->lang->line('amc_added'));
redirect("module=amc", 'refresh');
}
}
型号:
class Amc_model extends CI_Model
{
public function __construct()
{
parent::__construct();
}
public function addamc($data = array())
{
$amcData = array(
'cust_id' => $data['cust_id'],
'cust_name' => $data['cust_name'],
'cust_address' => $data['cust_address'],
'contact_person' => $data['contact_person'],
'location' => $data['location'],
'email' => $data['email'],
'prs' => $data['prs'],
'rating' => $data['rating'],
'hrs' => $data['hrs'],
'engine_num' => $data['engine_num'],
'model' => $data['model'],
'amc_from' => $data['amc_from'],
'amc_to' => $data['amc_to'],
'expiry_date' => $data['expiry_date'],
'no_visit_agreed' => $data['no_visit_agreed'],
'no_visit_made' => $data['no_visit_made'],
'date_commence' => $data['date_commence'],
'last_oil_ser_date' => $data['last_oil_ser_date'],
'last_visit_date' => $data['last_visit_date'],
'visit_due' => $data['visit_due'],
'visit_status' => $data['visit_status'],
'svc_status' => $data['svc_status'],
'amc_status' => $data['amc_status'],
'actual_amt' => $data['actual_amt'],
'amt_recieved' => $data['amt_recieved'],
'amt_due' => $data['amt_due'],
'payment_method' => $data['payment_method'],
'payment_due_date' => $data['payment_due_date'],
'assigned_to' => $data['assigned_to']
);
if($this->db->insert('amc_details', $amcData)) {
return true;
} else {
return false;
}
}
}
查看:
<?php $attrib = array('class' => 'form-horizontal'); echo form_open("module=amc&view=addamc", $attrib);?>
<table class="imagetable" align="center">
<tr>
<td width="180px" align="left" >Customer ID</td>
<td><input type="text" name="customer_id" id="customer_id" /></td>
<td align="center">Name</td>
<td><input type="text" name="cname" id="cname" /></td>
<td align="center">Address</td>
<td><input type="text" name="addr" id="addr" /></td>
</tr>
<tr>
<td>Location</td>
<td><input type="text" name="loc" id="loc" /></td>
<td align="center">Email ID</td>
<td ><input type="text" name="email" id="email" /></td>
<td align="center">Contact Person</td>
<td><input type="text" name="contact_prsn" id="contact_prsn" /></td>
</tr>
<tr>
<td>ENGINE No</td>
<td><input type="text" name="engine" id="engine" /></td>
<td align="center">Model</td>
<td><input type="text" name="model" id="model" /></td>
<td align="center">PRS</td>
<td><input type="text" name="prs" id="prs" /></td>
</tr>
<tr>
<td>Rating</td>
<td><input type="text" name="rating" id="rating" /></td>
<td align="center">HRS</td>
<td><input type="text" name="hrs" id="hrs" /></td>
<td align="center">Expiry Date</td>
<td><input type="text" name="expd" id="expd" /></td>
</tr>
<tr>
<td align="left">AMC From</td>
<td><input type="text" name="amcfrom" id="amcfrom" /></td>
<td align="center">AMC To</td>
<td><input type="text" name="amcto" id="amcto" /></td>
<td align="center">Date of Commencement</td>
<td><input type="text" name="doc" id="doc" /></td>
</tr> <tr>
<td align="left">No.of visit Agreed</td>
<td><input type="text" name="visagree" id="visagree" /></td>
<td align="center">No.of visit made</td>
<td><input type="text" name="vismade" id="vismade" /></td>
<td align="center">Last Oil Service Date</td>
<td><input type="text" name="losd" id="losd" /></td>
</tr>
<tr>
<td align="left">Last Visit Date</td>
<td><input type="text" name="lvd" id="lvd" /></td>
<td align="center">Visit due every after</td>
<td><input type="text" name="visitdue" id="visitdue" /></td>
<td align="center">SVC Status</td>
<td><input type="text" name="svcstatus" id="svcstatus" /></td>
</tr>
<tr>
<td align="left">Visit Status</td>
<td><input type="text" name="visitstatus" id="visitstatus" /></td>
<td align="center">AMC Status</td>
<td><input type="text" name="amcstat" id="amcstat" /></td>
<td align="center">Actual Amount</td>
<td><input type="text" name="actualamt" id="actualamt" /></td>
</tr>
<tr>
<td align="left"> Amount Recieved</td>
<td><input type="text" name="amtrecieved" id="amtrecieved" /></td>
<td align="center">Amount Due</td>
<td><input type="text" name="amountdue" id="amountdue" /></td>
<td align="center">Payment Method</td>
<td><input type="text" name="paymentmethod" id="paymentmethod" /></td>
<td></td>
</tr>
<tr>
<td align="left">Payment Due Date</td>
<td><input type="text" name="paymentdue" id="paymentdue" /></td>
<tr>
<td>
<?php echo form_submit('submit', $this->lang->line("submit"), 'class="btn btn-primary" style="padding: 6px 15px;"'); ?>
</tr>
</tr>
</table>
<?php echo form_close();?>
我是 codeigniter 的菜鸟,我找不到代码有什么问题。谁能帮我解决这个问题..
最佳答案
在您的 Controller 中,只有当验证为真时,您才应调用插入代码。
$this->amc_model->addamc($data);
我应该在 Controller 函数 addamc() 中进行更改。最终代码将是
function addamc()
{
$data = array('cust_id' => $this->input->post('customer_id'),
'cust_name' => $this->input->post('cname'),
'cust_address' => $this->input->post('addr'),
'contact_person' => $this->input->post('contact_prsn'),
'location' => $this->input->post('loc'),
'email' => $this->input->post('email'),
'prs' => $this->input->post('prs'),
'rating' => $this->input->post('rating'),
'hrs' => $this->input->post('hrs'),
'engine_num' => $this->input->post('engine'),
'model' => $this->input->post('model'),
'amc_from' => $this->input->post('amcfrom'),
'amc_to' => $this->input->post('amcto'),
'expiry_date' => $this->input->post('expd'),
'no_visit_agreed' => $this->input->post('visagree'),
'no_visit_made' => $this->input->post('vismade'),
'date_commence' => $this->input->post('doc'),
'last_oil_ser_date' => $this->input->post('losd'),
'last_visit_date' => $this->input->post('lvd'),
'visit_due' => $this->input->post('visitdue'),
'visit_status' => $this->input->post('visitstatus'),
'svc_status' => $this->input->post('svcstatus'),
'amc_status' => $this->input->post('amcstat'),
'actual_amt' => $this->input->post('actualamt'),
'amt_recieved' => $this->input->post('amtrecieved'),
'amt_due' => $this->input->post('amountdue'),
'payment_method' => $this->input->post('paymentmethod'),
'payment_due_date' => $this->input->post('paymentdue'),
'assigned_to' => 'not assigned'
);
if ( $this->form_validation->run() == true)
{
$result = $this->amc_model->addamc($data);
if($result == true) {
$this->session->set_flashdata('success_message', $this->lang->line('amc_added'));
redirect("module=amc", 'refresh');
} else {
//insertion failed
}
}
}
仅当验证为真时,才必须执行插入语句。
关于php - Codeigniter- 即使在页面加载或刷新时也将空白行插入到 mysql 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26945117/
我正在使用 LinqToExcel 轻松地将 Excel 数据导入 SQL Server。 var fileName = ConfigurationManager.AppSetting
在我的 MVVM WPF 应用程序中,我使用的是数据绑定(bind)流文档。我使用了 here 描述的技术能够将我的数据绑定(bind)到流文档。 我的流文档绑定(bind)到我的 View 模型中的
好吧,这很难解释。 场景: 我有一个 DataGrid 定义如下: 它有两个 header ,我需要添加数据,我做了很多研究建议使用 Obs
如果用户单击 DataGridView 底部的空白行并将焦点从 DataGridView 移开,则现在单击的行将处于指示对该行进行更改的状态。 是否可以告诉 DataGridView 取消将此行标记为
我必须迭代行并将其添加到列表中,但我得到的总行数是 Excel 工作表中存在的总行数,即 1001 行,但我只有 3 行,包括标题,我必须停止使用行号的大小进行循环。 我的代码是 Sheet
我有一个 csv 文件,其中包含必须从中删除的信息(通过删除相应的列来完成),我得到的输出是我所期望的,除了每行之间还给我空白行。我怎样才能摆脱那些? (我目前没有pandas,所以如果有解决这个问题
我是一名优秀的程序员,十分优秀!