EDIT: I think I found a way to do it. It is not pretty and I know that I need to use prepared statements. (I'm working my way up to understanding them.)
// look up utilization_id
$sql_utilization_id = "SELECT id FROM system_utilization ORDER BY id
DESC LIMIT 1";
$query_utilization_id = mysqli_query($link, $sql_utilization_id);
$result_utilization_id = mysqli_fetch_assoc($query_utilization_id);
$util_id=implode($result_utilization_id);
$new_util_id=intval($util_id)+1;
$sql = "INSERT INTO system_utilization (date_used, bunker_id, user_id, use_id, hours_used, activity_description) VALUES ('$date', '$bunker_id', '$user_id', '$use_id', '$hours_used', '$activity_description');
INSERT INTO system_meters (image_hours, treatment_hours, power_on_hours, gantry_revolutions, kv_energy_delivered, kv_image_hours, kv_amp_seconds, kv_num_exposures) VALUES ('$image_hours', '$treatment_hours', '$power_on_hours', '$gantry_revolutions', '$kv_energy_delivered', '$kv_image_hours', '$kv_amp_seconds', '$kv_num_exposures');
INSERT INTO hw_modifications (subsystem_id, component_id, manufacturer_id, new_pn, new_sn, new_fw, new_rev_id, old_pn, old_sn, old_fw, old_rev_id) VALUES ('$subsystem_id', '$component_id', '$manufacturer_id', '$new_pn', '$new_sn', '$new_fw', '$new_rev_id', '$old_pn', '$old_sn', '$old_fw', '$old_rev_id');
INSERT INTO failures_and_interrupts (component_id, error_message, actions_taken, utilization_id) VALUES ('$component_id_fail', '$error_message', '$actions_taken','$new_util_id')";
I am very new to SQL and coding in general. I am trying to learn as I go on this task. Please forgive me if I am ignorant of a simple solution.
I have been tasked with creating an equipment log book in a database. I am teaching myself PHP to create the code. I am using MySQL for my database.
I have several tables that may or may not have data inserted into them if they are not needed.
Tables:
system_meters system_utilization hw_modifications sw_modifications failures_and_interrupts
system_meters and system_utilization will be filled out on every use of the equipment. system_utilization has a column 'id' that will be used as a key 'utilization_id' on all of the other tables. 'id' will auto-increment whenever the table has a new row inserted.
Is there a way to have 'id' populate into 'utilization_id' whenever one of the other tables is updated?
Example: I change a piece of hardware. I fill out the necessary columns in system_utilization, system_meters, and hw_modifications. How would I have the 'id' from system_utilization inserted into the 'utilization_id' of the other 2 tables?