Hello,
i'm having 2 tables one is CLG and other is STUD.
in CLG(columns CID-autoincrement and CName) and in
STUD( three columns are ID-autoincrement,Name and CID)

> im using this code to store the records into tables

$sql="INSERT INTO clg (Cname) VALUES ('$_POST[cname]')";
$id=mysql_insert_id();

$sl="INSERT INTO stud (name,CID) VALUES ('$_POST[name]',".$id.")";

by using this.. records are getting stored into the CLG table but.. are not getting stored in STUD table...showing an null/empty value in the NAME and CID column of STUD table.

Please Help !

Recommended Answers

All 3 Replies

try this instead

$sl="INSERT INTO stud (name,CID) VALUES ('$_POST[name]','$id')";

PS also try echoing the $id to make sure there is a value

Hello,
i'm having 2 tables one is CLG and other is STUD.
in CLG(columns CID-autoincrement and CName) and in
STUD( three columns are ID-autoincrement,Name and CID)

> im using this code to store the records into tables

$sql="INSERT INTO clg (Cname) VALUES ('$_POST[cname]')";
$id=mysql_insert_id();

$sl="INSERT INTO stud (name,CID) VALUES ('$_POST[name]',".$id.")";

by using this.. records are getting stored into the CLG table but.. are not getting stored in STUD table...showing an null/empty value in the NAME and CID column of STUD table.

Please Help !

Have you put $sl in a mysql query like this mysql_query($sl)

i dont know why mysql_insert_id(); was always returning zero..
so i did this...

$result = mysql_query("SELECT id FROM clg ORDER BY id DESC LIMIT 1");
    $stuff = mysql_fetch_assoc($result);

Thanks for your support Guys !!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.