Welcome Guest, Not a member yet? Register   Sign In
Stored Procedure is not working
#1

[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">
&lt;html &gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;form id="frm-edit-test" method="post" &gt;
<p>
<label for="txt_fname">First Name:</label>
&lt;input type="text" id="txt_fname" name="txt_fname" value="&lt;?php echo $single_test['Fname']?&gt;" /&gt;
</p>


<p>
    <label for="txt_lname">Last Name:</label>
    &lt;input type="text" id="txt_lname" name="txt_lname" value="&lt;?php echo $single_test['Lname'] ?&gt;"/&gt;
</p>

<p>
&lt;input type="submit" id="btn_save" name="btn_save" value="save"/&gt;
</p>
<a href = "&lt;?php echo base_url().">Back</a>
&lt;/form&gt;

&lt;/body&gt;
&lt;/html&gt;

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
#2

[eluser]Rahul gamit[/eluser]
i have found this link http://ellislab.com/forums/viewthread/73714/ and it helped me.
#3

[eluser]Unknown[/eluser]
dsfwefwe
#4

[eluser]Jaketoolson[/eluser]
So calling the procedure from a MySQL command prompt, or using a GUI interface like PHPMyAdmin, you are able to do so with no problems?




Theme © iAndrew 2016 - Forum software by © MyBB