insert array into database codeigniter?

i have tried to make sql code in CI, the problem is the ID_LABEL at t_publisher is filled with 0 where it should filled with number that taken from t_label..

$sql['query1'] = "INSERT into t_user (USER_NAME, USER_PASS, USER_STATUS, USER_TYPE) values ('$user', '$pass','1','publisher')";

$sql['query2'] = "INSERT INTO t_label (LABEL) values('$user')";

$id_label = "select id_label from t_label where label ='".$user."'";

$id = $this->db->query($id_label)->result();

$sql['query3'] = "INSERT INTO t_publisher (PUBLISHER, ARTIS, ID_LABEL) values('$user', 'Various Artist', '$id')";

$result = array();

foreach($sql as $key => $value){

$result[$key] = $this->db->query($value);

}

please help :)

Comments

  • Not really sure how your database works.

    At least, you might check your output for each line, probably starting after second sql[query2].

    Some query might missed out, therefore you have null from your query.

    Or, perhaps, your t_label not filled correctly, your selection returns null from empty fields.

    Good luck there.

  • Im not sure this code works : $id = $this->db->query($id_label)->result(); It still in array form.

    Alternative:

    $id_label = "select id_label from t_label where label =".$user.";

    $id = $this->db->query($id_label);

    foreach ($id->result() as $row){

    $labelId = $row-> id_label;

    }

    Important:

    Use escape function before submit the query.

    http://www.web-experiences.co.cc/2012/10/escaping-...

Sign In or Register to comment.