2

I've two different table, 1st is draft_table, and 2nd is fix_table, each table have same fields ( product & price )

i want to make data from draft_table, can be save to fix_table with checkbox, so just selected data will save to fix_table.

i've code like this :

AJAX

<script>
$(function(){
    $("a.paid").click(function(){
    if(confirm("Are you sure want save this?"))
    {
        id_array=new Array()
        i=0;
        $("input.chk:checked").each(function(){
            id_array[i]=$(this).val();
            i++;
        })

        $.ajax({
            url:'<?php echo base_url(); ?>fix_data/set',
            data:"kode="+id_array,
            type:"POST",
            success:function(respon)
            {
                if(respon==1)
                {
                    window.parent.location.reload(true);
                }
            }
        })
    }
        return false;
    })
})
</script>

Views :

<?php
    foreach($data_get->result_array() as $dp)
    {
?>      
    <tr><td><input type="checkbox" name="chk[]" class="chk" value="<?php echo $dp['id_draft']; ?>" /></td>
    <td><?php echo $dp['product']; ?></td>
    <td><?php echo $dp['price']; ?></td>
    </td></tr>
<?php
    }
?> 

Controller :

public function set_stts()
{
    if($this->session->userdata('logged_in')!="")
    {
        $id_get = $this->input->post('kode');
        $dt = $this->db->get_where("tbl_draft",$id_get)->row();
        $product = $dt->product;
        $price = $dt->price;
        if ($this->input->post('kode')) {   
            $query = $this->db->query("INSERT INTO tbl_fix (product,price) VALUES (".$product.",".$price.")");
        }

        if($query){
            echo 1;
        }
        else{
            echo 0;
        }
    }
    else
    {
        header('location:'.base_url().'dashboard_item');
    }
}

After i Click submit in draft form, nothing happen, is there anyone may help me with this case?

Thank you

3
  • side note: you never increase the $no2 in the cycle. Commented Dec 5, 2018 at 15:13
  • i already delete it, it just for another function, not related with code.. Commented Dec 5, 2018 at 15:33
  • there is an url mismatch in ajax and controller method name.your calling set method while controller has set_stts method and also $id_get variable is an array Commented Dec 6, 2018 at 5:25

1 Answer 1

1

maybe you can change your controller like this :

public function set()
    {
        if($this->session->userdata('logged_in')!="")
        {
            $id_get = $this->input->post('kode');
            $quer = $this->db->query("select * from tbl_draft WHERE id IN (".$id_get.")");
            if ($this->input->post('kode')) {   
                foreach($quer->result_array() as $dp)
                {
                    $a = $dp['product'];
                    $b = $dp['price'];
                    $query = $this->db->query("INSERT INTO tbl_fix (product,price) VALUES 
                    ('".$a."','".$b."')");
                }
            }

            if($query){
                echo 1;
            }
            else{
                echo 0;
            }
        }
        else
        {
            header('location:'.base_url().'dashboard_item');
        }
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.