发生数据库错误错误编号:代码指示器中的1146 [英] A Database Error Occurred Error Number: 1146 in codeignitor
本文介绍了发生数据库错误错误编号:代码指示器中的1146的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码:
<?php echo validation_errors(); >
<?php echo form_open('inquiry'); >
< table width =580border =0cellspacing =0cellpadding =5>
< tr>
< td height =30align =rightvalign =middleclass =normal-text-style> *全名:< br />< / td>
< td height =30align =leftvalign =middleclass =normal-style>< input type =textname =namevalue =< ;? php echo set_value('name');?> class =textbox-style01/>< / td>
< / tr>
< tr>
< td height =30align =rightvalign =middleclass =normal-text-style> *公司:< span id =mndCompany> < / span>< br />< / td>
< td height =30align =leftvalign =middleclass =normal-style>< input type =textname =companyvalue =< ;? php echo set_value('company');?> class =textbox-style01/>< / td>
< / tr>
< tr>
< td height =30align =rightvalign =middleclass =normal-text-style> *电子邮件:< / td>
< td height =30align =leftvalign =middleclass =normal-style>< input type =textname =emailvalue =< ;? php echo set_value('email');?> class =textbox-style01/>< / td>
< / tr>
< tr>
< td height =30align =rightvalign =middleclass =normal-text-style> *电话:< br />< / td>
< td height =30align =leftvalign =middleclass =normal-style>< input type =textname =phonevalue =< ;? php echo set_value('phone');?> class =textbox-style02/>< / td>
< / tr>
< tr>
< td height =30align =rightvalign =middleclass =normal-text-style> *传真:< br />< / td>
< td height =30align =leftvalign =middleclass =normal-style>< input type =textname =faxvalue =< ;? php echo set_value('comments');?> class =textbox-style01/>< / td>
< / tr>
< tr>
< td width =179height =30rowspan =2align =rightvalign =topclass =normal-text-style> *评论:< br />< / td>
< td width =421height =12align =leftvalign =middleclass =normal-style>< textarea name =commentsclass =msgebox-style01 ><?php echo set_value('comments'); ?>< / textarea>< / td>
< / tr>
< tr>
< td height =50align =leftvalign =topclass =normal-style>< input type =imagename =submitsrc =< ;? php echo base_url();?> /public/images/submit01.pngalt =submit/>< / td>
< / tr>
< / table>
< / form>
这是我的控制器
function index()
{
$ this-> form_validation-> set_rules('name','Name','trim | required | xss_clean');
$ this-> form_validation-> set_rules('company','Company','trim | required | xss_clean');
$ this-> form_validation-> set_rules('email','Email','required | valid_email | is_unique [users.email]');
$ this-> form_validation-> set_rules('phone','phone','trim | required | xss_clean');
$ this-> form_validation-> set_rules('fax','fax','trim | required | xss_clean');
$ this-> form_validation-> set_rules('comments','comments','trim | required | xss_clean');
$ data ['header_menu'] = $ this-> load-> view('header_menu','',TRUE);
$ this-> load-> view('inner_header',$ data);
$ data ['left_menu'] = $ this-> load-> view('left_menu','',TRUE);
if($ this-> form_validation-> run()== FALSE)
{
$ this-> load-& $ data);
}
else
{
$ this-> load-> view('inquiry / formsucess',$ data);
}
$ this-> load-> view('footer');
// $ this-> load-> view('inquiry',$ data);
}
function formsucess()
{
$ name = $ this-> input-> post('name');
$ company = $ this-> input-> post('company');
$ email = $ this-> input-> post('email');
$ phone = $ this-> input-> post('phone');
$ fax = $ this-> input-> post('fax');
$ comments = $ this-> input-> post('comments');
$ this-> db-> query(INSERT INTO`st_enquiry`
(名称,公司,电子邮件,电话,传真,评论,状态,created_on)
VALUES
('$ name','$ company','$ email','$ phone','$ fax','$ comments','1',now
$ data ['header_menu'] = $ this-> load-> view('header_menu','',TRUE);
$ this-> load-> view('inner_header',$ data);
$ data ['left_menu'] = $ this-> load-> view('left_menu','',TRUE);
$ this-> load-> view('media',$ data);
$ this-> load-> view('footer');
}
提交表单后发生错误如:
发生数据库错误
错误号码:1146
表'table.users'不存在
请帮助我提前感谢。
解决方案
此处
$ data = array(
'title'=>'My title',// column_name => value
'name'=>'My Name',
'date'=>我的日期'
);
$ this-> db-> insert('tablename',$ data);
必须在任何条件下工作。
I am new to codeignitor where I tried form validation.
Here is my View Code:
<?php echo validation_errors(); ?>
<?php echo form_open('enquiry'); ?>
<table width="580" border="0" cellspacing="0" cellpadding="5">
<tr>
<td height="30" align="right" valign="middle" class="normal-text-style"> *Full Name:<br /></td>
<td height="30" align="left" valign="middle" class="normal-style"><input type="text" name="name" value="<?php echo set_value('name'); ?>" class="textbox-style01" /></td>
</tr>
<tr>
<td height="30" align="right" valign="middle" class="normal-text-style"> *Company: <span id="mndCompany"> </span><br /></td>
<td height="30" align="left" valign="middle" class="normal-style"><input type="text" name="company" value="<?php echo set_value('company'); ?>" class="textbox-style01" /></td>
</tr>
<tr>
<td height="30" align="right" valign="middle" class="normal-text-style"> *E-mail:</td>
<td height="30" align="left" valign="middle" class="normal-style"><input type="text" name="email" value="<?php echo set_value('email'); ?>" class="textbox-style01" /></td>
</tr>
<tr>
<td height="30" align="right" valign="middle" class="normal-text-style"> *Phone: <br /></td>
<td height="30" align="left" valign="middle" class="normal-style"><input type="text" name="phone" value="<?php echo set_value('phone'); ?>" class="textbox-style01" /></td>
</tr>
<tr>
<td height="30" align="right" valign="middle" class="normal-text-style"> *Fax: <br /></td>
<td height="30" align="left" valign="middle" class="normal-style"><input type="text" name="fax" value="<?php echo set_value('comments'); ?>" class="textbox-style01" /></td>
</tr>
<tr>
<td width="179" height="30" rowspan="2" align="right" valign="top" class="normal-text-style"> *Comments: <br /></td>
<td width="421" height="12" align="left" valign="middle" class="normal-style"><textarea name="comments" class="msgebox-style01"><?php echo set_value('comments'); ?></textarea></td>
</tr>
<tr>
<td height="50" align="left" valign="top" class="normal-style"><input type="image" name="submit" src=" <?php echo base_url(); ?>/public/images/submit01.png" alt="submit" /></td>
</tr>
</table>
</form>
And this is my controller
function index()
{
$this->form_validation->set_rules('name', 'Name', 'trim|required|xss_clean');
$this->form_validation->set_rules('company', 'Company', 'trim|required|xss_clean');
$this->form_validation->set_rules('email', 'Email', 'required|valid_email|is_unique[users.email]');
$this->form_validation->set_rules('phone', 'phone', 'trim|required|xss_clean');
$this->form_validation->set_rules('fax', 'fax', 'trim|required|xss_clean');
$this->form_validation->set_rules('comments', 'comments', 'trim|required|xss_clean');
$data['header_menu']=$this->load->view('header_menu', '', TRUE);
$this->load->view('inner_header',$data);
$data['left_menu']=$this->load->view('left_menu', '', TRUE);
if ($this->form_validation->run() == FALSE)
{
$this->load->view('enquiry',$data);
}
else
{
$this->load->view('enquiry/formsucess',$data);
}
$this->load->view('footer');
//$this->load->view('enquiry',$data);
}
function formsucess()
{
$name = $this->input->post('name');
$company = $this->input->post('company');
$email = $this->input->post('email');
$phone = $this->input->post('phone');
$fax = $this->input->post('fax');
$comments = $this->input->post('comments');
$this->db->query("INSERT INTO `st_enquiry`
(name, company,email,phone,fax,comments,status,created_on)
VALUES
('$name','$company','$email','$phone','$fax','$comments','1',now())");
$data['header_menu']=$this->load->view('header_menu', '', TRUE);
$this->load->view('inner_header',$data);
$data['left_menu']=$this->load->view('left_menu', '', TRUE);
$this->load->view('media',$data);
$this->load->view('footer');
}
After submitting the form I got an error like:
A Database Error Occurred
Error Number: 1146
Table 'table.users' doesn't exist
Please help me thanks in advance.
解决方案
Here
$data = array(
'title' => 'My title' , // column_name => value
'name' => 'My Name' ,
'date' => 'My date'
);
$this->db->insert('tablename', $data);
must work in any condition.
这篇关于发生数据库错误错误编号:代码指示器中的1146的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文