The code inserts data into the database. I am having an issue with replacing one of the array value with a variable i.e I want to specify $fac_id as the value instead of fetching the value from an input field. When I execute the code, the value in db is empty but when I echo $fac_id
, I get a value for the logged in user such as 7
.
$current_user = wp_get_current_user();
$fac_id = get_current_user_id();
for ($i = 0; $i < count($_POST["service"]); $i++) {
$fields = [
1 => 'shifttype',
2 => 'shiftstype',
3 => ''.$fac_id.'',
4 => 'cvd',
7 => 'facname',
8 => 'facadd',
];
foreach ($fields as $formInputId => $inputValueKey) {
$d_id = '';
$appointmentid = $insertId;
$customerid = $custs->id;
$forminputid = $formInputId;
$inputvalue = $_POST[$inputValueKey][$i];
$inputfilename = 'NULL';
$insert_cust = "INSERT INTO wp_appointment_custom_data (id, appointment_id, customer_id, form_input_id, input_value, input_file_name) VALUES ('$d_id', '$appointmentid', '$customerid', '$forminputid', '$inputvalue', '$inputfilename')";
$query_run = mysqli_query ($que_cust, $insert_cust);
}
}