-1

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 !

3
Contributors
3
Replies
6
Views
7 Years
Discussion Span
Last Post by Vigasdeep
0

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

Edited by drjohn: n/a

0

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)

-1

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 !!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.