I am trying to learn MVC with phpcodeigniter. I got a project file with all the codes and my task is just to learn from them simply by running the files using xamp. All the bits are doing fine but, whenever I try to create a new user with the form, I get a an instant message next to the RTC-ID saying "user already existing" and the submit button disappears! even though there is no data loaded in the database (tried to upload the image for this issue but I am not permitted to do so). I am trying to find out why this error is showing up. I have tried to look up where this issue is from and found this codes acting on the form and the data. These are some of the code snippets which creates the new user. I have tried to solve this issues for many days. I will be really grateful if someone could kindly help me solve the issue and I am not sure if I am posting at the right forum my apologies. Thank you!
views/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>
Controller/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');
}
}
models/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);
}
models/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);
}
}