I am using Codeigniter and I have created a code that checks if there is the same entry already in the database. but i dont know how i will output the error message. the boolean is not working.
VIEW
<h8><b>Add New Service: For single upload. <?php echo $status; ?></b></h8><hr>
<form action="<?php echo base_url(); ?>some_controller/insertServ" method="post">
<center>Service Name: <input type="text" name="ci_name"/>
<input type="submit" class="classname" value="Save"/></center>
</form>
CONTROLLER
public function insertServ(){
/* logic behind adding a new service
*/
$ci_name = $this->input->post('ci_name');
$success = $this->some_model->addCI($ci_name);
if($success == TRUE)
$this->viewMap_add(TRUE);
else $this->viewMap_add(FALSE);
}
public function viewMap_add($success = NULL){
/* Shows the list of the services with a dialog box for
* adding a new service
*/
if($success == NULL)
$status = 'N/A';
else if($success == TRUE)
$status = 'Success';
else $status = 'FAILED';
$data['status'] = $status;
$data['current_user']=$this->session->userdata('email');
$data['mapList'] = $this->some_model->getMapped();
$this->load->view('templates/header.php',$data);
$this->load->view('some_page/servList_add.php',$data);
}
MODEL
public function addCI($ci_name){
/* Adds a new service
*/
$ci_name = $this->db->escape_str($ci_name);
$queryStr = "Select service from appwarehouse.service where service = '$ci_name'";
$query = $this->db->query($queryStr);
if($query->num_rows()>0){
echo "result already exists";
}
else{
$queryStr = "INSERT INTO appwarehouse.service(service) VALUES ('$ci_name');";
$query = $this->db->query($queryStr);}
}