This topic is locked

Custome Dropdown Value doesn't insert to another table (production_shedule table)

8/3/2024 4:52:35 PM
PHPRunner General questions
J
jackwood author

Hi,

Need your help to post the value of the custom dropdown to another table production_shedule

img alt

I've created custom dropdown (inhouse/subcont)

// Put your code here.
echo '<div class="custom-dropdown-container">
<label for="dropdown_process_type">Apply Order to:</label>
<select id="select_process_type" name="select_process_type">
<option value="">Select...</option>
<option value="inhouse">Inhouse</option>
<option value="subcont">Subcontractor</option>
</select>
</div>
';

after record updated
===========================================

// Pastikan data dikirim dengan metode POST
$process_type = isset($_POST['select_process_type']) ? $_POST['select_process_type'] : '';

// Ambil order_id dan order_detail_id dari record yang diupdate
$order_id = $values['order_id'];
$order_detail_id = $values['order_detail_id'];
$tenant_id = $values['tenant_id'];
$product_id = $values['product_id'];

$quantity = $values['quantity'];
$schedule_date = $values['schedule_date']; // Asumsi schedule_date adalah tanggal saat ini, bisa diubah sesuai kebutuhan
$inhouse_process = $values['inhouse_process'] ;

// Cek jika jadwal sudah ada
$sql = "SELECT * FROM production_schedule WHERE order_id = {$order_id} AND order_detail_id = {$order_detail_id}";
$rs = DB::Query($sql);
$data = $rs->fetchAssoc();

if ($data) {
// Update existing schedule
$updateData = array(
"process_type" => $process_type,
"schedule_date" => $schedule_date,
"product_id" => $product_id,
"inhouse_process" => $inhouse_process,
"tenant_id" => $tenant_id
);
DB::Update("production_schedule", $updateData, "order_id = {$order_id} AND order_detail_id = {$order_detail_id}");
} else {
// Insert new schedule
$insertData = array(
"order_id" => $order_id,
"order_detail_id" => $order_detail_id,
"process_type" => $process_type,
"schedule_date" => $schedule_date,
"product_id" => $product_id,
"quantity" => $quantity,
"inhouse_process" => $inhouse_process,
"tenant_id" => $tenant_id
);
DB::Insert("production_schedule", $insertData);
}

// Update status salesorder menjadi 'Processed'
$updateOrderData = array("status_id" => 2); // Status 'Processed'
DB::Update("salesorder", $updateOrderData, "order_id = {$order_id}");

------------------------------

This code success insert to another table (production_schedule), but the value of select_process_type not included

Sergey Kornilov admin 8/4/2024

Your code relies on variables like $process_type but these variables are not defined anywhere in your code.

J
jackwood author 8/5/2024

Hi Sergey,

In This Code:
$process_type = isset($_POST['select_process_type']) ? $_POST['select_process_type'] : '';

Where should I do define the code ? need your help, maybe it will helpful for another member.

Sergey Kornilov admin 8/5/2024

I see that $process_type variable is a part of both Insert and Update statements. So, it needs to be defined before it is being used, somewhere in the beginning of your code. And the same applies to all PHP variables, they need to be defined before you use them.