Welcome Guest, Not a member yet? Register   Sign In
Urgent HELP needed
#1

[eluser]Aniket Pant[/eluser]
I have a page in which i am taking a few inputs from a user using form_input().
Now, these inputs are in different fields like this-

Code:
echo form_open('admin/enter_product');
        echo form_input('id', 'ID');
        echo form_input('name', 'Name');
        echo form_input('short_name', 'Short Name');
        $product = array(
                  'tshirt'  => 'T-Shirt',
                  'watch'    => 'Wrist Watch',
                );
        echo form_dropdown('product', $product);
        echo form_input('product_desc', 'Product Description');
        echo form_input('price', 'Price');
        echo form_input('disc1', 'Discount 1');
        echo form_input('disc2', 'Discount 2');
        echo form_submit('submit', 'Submit');

but when i try to insert these values in my table 'data', it turns all the number related fields which are price, disc1 and disc2 to ZERO.
Code:
$id = $this->input->post('id');
        $name = $this->input->post('name');
        $short_name = $this->input->post('short_name');
        $product = $this->input->post('product');
        $product_desc = $this->input->post('product_desc');
        $price = (float)$this->input->post('$price');
        $disc1 = (float)$this->input->post('$disc1');
        $disc2 = (float)$this->input->post('$disc2');
        
        $q = "INSERT INTO data VALUES ('$id', '$name', '$short_name', '$product', '$product_desc', $price, $disc1, $disc2)";
        $this->db->query($q);

The structure of table 'data' is:
id, name, short_name, product, product_desc - varchar
price, disc1, disc2 - int

Please tell me what to do
#2

[eluser]Aniket Pant[/eluser]
Sorry, very idiotic error... fixed it Smile

No need to reply Big Grin




Theme © iAndrew 2016 - Forum software by © MyBB