I have created an audit trail to record the creation of a new list of selected categories against a newly created service provider.
The problem I am having is that it is only posting the first record to the database table even though I have included the audit trail within the foreach statement. The same audit trail has worked fine in other areas of the database, but this is the only one where I have used it in relation to an array and a foreach statement so am wondering if I am doing something wrong with that.
Code below......................
foreach ($_POST['selected_cat'] as $levelc_lk) {
$querycatcodes = "SELECT * FROM $table_cat_level3 WHERE levelc_lk = '$levelc_lk'";
$result_querycatcodes = MYSQL_QUERY ($querycatcodes);
$levelb_lk=mysql_result($result_querycatcodes,0,"l evelb_lk");
$levela_lk=mysql_result($result_querycatcodes,0,"l evela_lk");
$insert="INSERT INTO $table_main (clientid,levela_lk,levelb_lk,levelc_lk) VALUES ('$clientid','$levela_lk','$levelb_lk','$levelc_lk ')";
MYSQL_QUERY($insert);
//audit trail -----------------------------------------------------------------------------------------
$type="Create";
$field="Cat Record";
$userid=$_SESSION['user_id'];
$old_data="Not Applicable";
$new_data="$levelc_lk";
$audit="INSERT INTO $table_audit_main (userid, clientid, type, field, old_data, new_data) VALUES ('$userid','$clientid','$type','$field','$old_data ','$new_data')";
MYSQL_QUERY($audit);
//------------------------------------------------------------------------------------------------------
}
Any help appreciated.
Submit Your Article
Forum Rules

Reply With Quote
