我正在尝试用phpcodeigniter学习MVC。我得到了一个包含所有代码的项目文件,我的任务只是通过使用xamp运行文件来向他们学习。所有这些都很好但是,每当我尝试使用表单创建一个新用户时,我会在RTC-ID旁边收到一条即时消息,说“用户已经存在"并且提交按钮消失了!即使数据库中没有加载数据(尝试上传此问题的图像,但我不允许这样做)。我试图找出这个错误出现的原因。我试图查找此问题的来源,并发现此代码作用于表单和数据。这些是创建新用户的一些代码段。我试图解决这个问题很多天了。如果有人能帮助我解决问题,我将非常感激,我不确定我是否在正确的论坛上发帖道歉。谢谢!
视图/ rtc.php
<!--FORM STARTS HERE-->
<form action="<?= site_url('form/rtc_insert'); ?>" method="post">
<label >RTC ID:<span id="rtc_reg_id_re" style="font-size:12px;float:right;"></span></label>
<input type="text" name="id" id="rtc_reg_id" placeholder="RTC ID" required/>
<label >Name:</label>
<input type="text" name="name" placeholder="Name" required/>
<label >Country:</label>
<select name="country" >
<option>Select Country</option>
<option value="Bangladesh">New zealand</option>
</select><br/><br/>
<label >District:</label>
<input type="text" name="state" placeholder="District" required/>
<label >Village:</label>
<input type="text" name="city" placeholder="Village" required/>
<label >Address:</label>
<textarea type="text" name="address" placeholder="Address" required/></textarea>
<input type="submit" value="Save" id="rtc_reg_submit" class="button"><br/>
</form>
控制器/ form.php的
function rtc_insert()
{
$session_user=$this->session->userdata('logged_in');
if($session_user['ath']=='admin')
{
$msg = $this->form_model->rtc_ins();
redirect('form/rtc/You Have Successfully Created '.$msg);
}
else
{
echo ' <script type="text/javascript">
alert("Access Error....");
</script>';
redirect('login/home');
}
}
模型/ form_model.php
function rtc_ins()
{
$session_user=$this->session->userdata('logged_in');
$sysdat = date("Y-m-j H:i:s");
$data= array(
'id' => $this->input->post('id'),
'name' => $this->input->post('name'),
'country' => $this->input->post('country'),
'city' => $this->input->post('city'),
'state' => $this->input->post('state'),
'address' => $this->input->post('address'),
'cre_name' => $session_user['username'],
'cre_date' => $sysdat
);
$this->db->insert('rtc_info',$data);
return $this->input->post('id');
// echo "<pre>";
// print_r($_POST);
}
模型/ ajax_models.php
public function rtc_reg_id($id)
{
$query = $this->db->get_where('rtc_info',array('id' => $id));
$query = $query->num_rows();
if($query > 0)
return 1;
else
return 0;
}
JS / ajax.js
function rtc_reg_id(){
var rtc_name = $('#rtc_reg_id').val();
if(rtc_name.length > 0)
{
$.post(base_url()+'ajax/rtc_reg_id/'+rtc_name,function(data){
if(data==0){
$('#rtc_reg_id_re').css({'color':'green'});
$('#rtc_reg_id_re').html('Available');
$('#rtc_reg_submit').attr('type','submit').show(100);
}
else{
$('#rtc_reg_id_re').css({'color':'red'});
$('#rtc_reg_id_re').html('ID Already Existing');
$('#rtc_reg_submit').attr('type','').hide(100);
}
});
}
else
{
$('#rtc_reg_id_re').empty();
$('#rtc_reg_submit').attr('type','submit').show(100);
}
}