Welcome Guest, Not a member yet? Register   Sign In
function add() and insert into tabble
#1

[eluser]Unknown[/eluser]
Hi everyone,
I want in database save data from send form. Function for storage is here:
Code:
function add()
    {    
        $data = array(
                        'title'    =>  ( ! isset($this->lang['scaff_add'])) ? 'Add Data' : $this->lang['scaff_add'],
                        'fields' => $this->CI->db->field_data($this->current_table),
                        'action' => $this->base_uri.'/insert'
                    );
    
        $this->CI->load->view('add', $data);
    }

and her calls:
Code:
function add($type,$one="",$two="",$three=""){
        $type = str_replace("-", "_", $type);
        $sql = "INSERT INTO table$type (one,two,three) VALUES ('$one','$two','$three')";
        $query = $this->ci->db->query($sql);
        if($query AND $query_sort){
            return true;
        }else{
            return false;
        }
    }
This is OK.

But I need 4 variables saved in table:
Code:
function add($type,$one="",$two="",$three="",$four=""){
        ...
        $sql = "INSERT INTO table$type (one,two,three,four) VALUES ('$one','$two','$three','$four')";
        ...
    }
But column "four" is always empty :/ When that I try this:
Code:
function add($type,$one="",$two="",$four=""){
        ...
        $sql = "INSERT INTO table$type (one,two,four) VALUES ('$one','$two','$four')";

Column "four" is not now empty...

And I needed function add() extend so, to work up all four parameters...

I'm so sorry for my english and thanks for help Smile
#2

[eluser]InsiteFX[/eluser]
Because you need to pass all columns!

Enjoy
InsiteFX
#3

[eluser]Unknown[/eluser]
What do you think please? All columns?

Thank you
#4

[eluser]BrianDHall[/eluser]
Check empty() on $four - if it isn't set at the beginning of the function, then somehow you aren't passing the function that variable. I presume your form is missing something?




Theme © iAndrew 2016 - Forum software by © MyBB