how would i pass a auto incremented primary key to a foreign key?
example i have this room table that has a Room_No as a primary key that is auto_increment and i need it to pass to another table named AF and Room_No as its foreign key..
what code should i write.
HELP!:?:

assuming you are using MySQL as your Database, as soon as you execute your INSERT statement, use the mysql_insert_id() function -
http://us3.php.net/manual/en/function.mysql-insert-id.php

to retrieve the auto_number.Then use that number to INSERT it into your AF table:

...

$sql="INSERT INTO `room`(...) VALUES(...)";

$result = mysql_query($sql) or die( mysql_error() );

$Room_No=mysql_insert_id();

$sql="INSERT INTO `AF`(`Room_No`) VALUES( $Room_No)";
mysql_query($sql) or die( mysql_error() );
...
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.