This topic is locked

Update table after record insert

9/21/2009 5:26:10 AM
PHPRunner General questions
R
ragrim author

hi, im trying to update a table with the User_ID of a record i just created, the user_id is an auto generated number created by mysql, how can i grab this number and use it to update my 2nd table?

J
Jane 9/21/2009

Hi,
you can select this value in the AfterSuccessfulLogin event on the Events tab, save it in the session variable and then use this variable in your code.

Here is a sample AfterSuccessfulLogin event:

global $dal;

$rstmp = $dal->UsersTableName->Query("Username='".$_SESSION["UserID"]."'","");

$datatmp = da_fetch_array($rstmp);

$_SESSION["User_ID"] = $datatmp["ID"];
R
ragrim author 9/21/2009

sorry i must not have it explained it right, what i have is a users table and a members table, user table holds all user personal info, and member tables holds membership info, basically member ID which is auto generated and membershiptype.
ive used the following code in the after update event to insert the user.user_id into the members.fkuser_id (fkuser_id is my foriegn key field to link the tables)


global $conn;
$uid = mysql_insert_id();

$strSQLInsert = "insert into members (FKUser_ID) values ($uid)";

db_exec($strSQLInsert,$conn);


the mysql_insert_id works great to grab the autonumber of the newly created user to create the member record, but i also need to grab the value of a combo box lookup table, ive tried using the $values but im not sure how to use it correctly.

J
Jane 9/21/2009

Hi,
you need to select lookup value manually if link and display fields (on the "Edit as" settings dialog) are different.