This topic is locked

After record added event redirect to another tables add page

11/14/2006 12:34:59 AM
PHPRunner General questions
jwoker author

I would like to have an after add event which redirects the user to another tables add page with a masterkey value. How can I get the id field of the record I just added? I have been unsuccessful with the code below but it should give a good idea of what I am trying to do.
Thanks

function AfterAdd()

{
//********** Check if specific record exists ************

global $conn;

$strSQLExists = "SELECT LAST_INSERT_ID()";

$rsExists = db_query($strSQLExists,$conn);

$data=db_fetch_array($rsExists);

if($data)

{

// if record exists do something

header("Location: Sales_job_add.php?mastertable=Sales_customer&masterkey1=".$data[0]);

exit();
}

else

{

// if dont exist do something else

}
}
Alexey admin 11/14/2006

Hi,
here is the code that should work:

function AfterAdd()

{

//** Check if specific record exists ****

global $conn;
$_SESSION["Sales_job_mastertable"]="Sales_customer";

$_SESSION["Sales_job_masterkey1"]=mysql_insert_id($conn);

header("Location: Sales_job_add.php);

exit();
}


Please note that both Sales_job and Sales_customer table names should be spelled exactly the same way as they are in the database.