[eluser]Rahul gamit[/eluser]
Hello Friends,
My stored procedure is not working. There is no error or problem while calling the procedure
here is my code,
CONTROLLER
Code:
<?php
class Controller_test extends CI_Controller
{
function __construct()
{
parent :: __construct();
$this->load->database();
$this->load->model('test/Model_test');
}
function add_test()
{
$this->load->view('test/View_Add');
if($this->input->post('btn_save'))
{
$this->Model_test->add_record();
redirect(base_url()."index.php/test/Controller_test/get_all_tests");
}
}
function edit_test($id)
{
$data['single_test'] = $this->Model_test->get_single_record($id);
$this->load->view('test/View_Edit',$data);
if($this->input->post('btn_save'))
{
$this->Model_test->edit_record($id);
echo $this->db->last_query();
//redirect(base_url()."index.php/test/Controller_test/get_all_tests");
}
}
function delete_test($id)
{}
function get_all_tests()
{
$data['test_list'] = $this->Model_test->get_all_records();
$this->load->view('test/View_List_All',$data);
}
}
?>
here is my model
MODEL
Code:
<?php
class Model_test extends CI_Model
{
public $Fname="";
public $Lname="";
function __construct()
{
parent::__construct();
$this->Fname=$this->input->post('txt_fname');
$this->Lname=$this->input->post('txt_lname');
}
function add_record()
{
$query = "CALL test_add(?,?)";
$result = $this->db->query($query,array($this->Fname,$this->Lname));
}
function edit_record($id)
{
/*$query = "CALL test_edit(?,?,?)";
$result = $this->db->query($query,array($id,$this->Fname,$this->Lname));*/
$data = array('Fname'=>$this->Fname,'Lname'=>$this->Lname);
$this->db->where('ID', $id);
$this->db->update('test', $data);
}
function delete_record()
{}
function get_all_records()
{
return $this->db->query("CALL test_select_all()")->result();
}
function get_single_record($id)
{
return $this->db->query("CALL test_select_single(?)",array($id))->row_array();
}
}
?>
and here is my view for editing the data
VIEW
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form id="frm-edit-test" method="post" >
<p>
<label for="txt_fname">First Name:</label>
<input type="text" id="txt_fname" name="txt_fname" value="<?php echo $single_test['Fname']?>" />
</p>
<p>
<label for="txt_lname">Last Name:</label>
<input type="text" id="txt_lname" name="txt_lname" value="<?php echo $single_test['Lname'] ?>"/>
</p>
<p>
<input type="submit" id="btn_save" name="btn_save" value="save"/>
</p>
<a href = "<?php echo base_url().">Back</a>
</form>
</body>
</html>
Here is my stored procedure for editing the table data
Code:
CREATE DEFINER=`root`@`localhost` PROCEDURE `test_edit`(IN p_ID int,
IN p_fname varchar(100),
IN p_lname varchar(100))
BEGIN
UPDATE test
SET Fname=p_fname,
Lname=p_lname
WHERE ID=p_ID;
END
I am not getting any error, but the records are not updated
Thanks in advance