Welcome Guest, Not a member yet? Register   Sign In
how to insert data from primary key column to foreign key
#1

[eluser]aqifilyaskhan[/eluser]
i am inserting data from a form i want when i will insert data so the first column primary id which is using in second column as a foreign key should be increased

i have tried this code but not working

first table code

$this->db->query("insert into af_ads (ad_title,ad_pic,ad_description)
values ('$title','$filepath','$description')");


second table code

$this->db->query("insert into af_category (cat_type,ad_id_fk)
values ('$category','ad_id')");


NOTE: i want to insert ad_id into ad_id_fk
#2

[eluser]sanir[/eluser]
use following code

Code:
$this->db->query(“insert into af_ads (ad_title,ad_pic,ad_description)
values (’$title’,’$filepath’,’$description’)”);
$ad_id = $this->db->insert_id;

$this->db->query(“insert into af_category (cat_type,ad_id_fk)
values (’$category’,$ad_id)”);





Theme © iAndrew 2016 - Forum software by © MyBB