1

I currently am able to pull the equipment name column from my table and input it into my av_events SQL. But I would like to be able to pull the serial column as well to put in my av_bookings table equipment column as it is unique identifier.

Here I am doing it but I would like to be able to do it with just one checkbox

Appreciate any help. Thanks

<table>
<?php while ($av_inventory = mysqli_fetch_assoc($subject_set)) { ?>
    <tr>
      <td><?php echo h($av_inventory['equipment']); ?></td>
      <td><?php echo h($av_inventory['product']); ?></td>
      <td><?php echo h($av_inventory['serial']); ?></td>
      <td><?php echo h($av_inventory['current_location']); ?></td>
      <td><?php echo h($av_inventory['status']); ?></td>
      <td><input name='checkbox[]' type='checkbox' value="<?php echo $av_inventory['equipment'];?>">
          <input name='checkbox2[]' type='checkbox' value="<?php echo $av_inventory['serial'];?>"></td>
     </tr>
<?php } ?>
</table>

$equipArray = implode(', ', $_POST['checkbox']);
$implodeArray = implode(',', $_POST['checkbox2']);
$explodeArray = explode(',', $implodeArray);

$_SESSION['location'];
$_SESSION['logins'];

$sqllogin = "INSERT INTO av_events";
$sqllogin .= "(event_name, equipment, site, engineer_name, vp_present, date_time_from, date_time_to)";
$sqllogin .= " VALUES (";
$sqllogin .= "'". $eventName. "',";
$sqllogin .= "'". $equipArray. "',";
$sqllogin .= "'". $_SESSION['location']. "',";
$sqllogin .= "'". $_SESSION['logins']. "',";
$sqllogin .= "'". $vpPres. "',";
$sqllogin .= "'". $dateFrom. "',";
$sqllogin .= "'". $dateTo. "'";
$sqllogin .= ")";
$result = mysqli_query($db, $sqllogin);

foreach ($explodeArray as $serialNumber){
    $sqllogin = "INSERT INTO av_bookings";
    $sqllogin .= "(event_name, equipment, site, engineer_name, date_time_from, date_time_to)";
    $sqllogin .= " VALUES (";
    $sqllogin .= "'". $eventName. "',";
    $sqllogin .= "'". $serialNumber. "',";
    $sqllogin .= "'". $_SESSION['location']. "',";
    $sqllogin .= "'". $_SESSION['logins']. "',";
    $sqllogin .= "'". $dateFrom. "',";
    $sqllogin .= "'". $dateTo. "'";
    $sqllogin .= ")";
    $result = mysqli_query($db, $sqllogin);
}

1 Answer 1

1

One could combine the information, then split it again afterwards. As a very rough guide:

<input name='checkbox[]' type='checkbox' value="<?php echo $av_inventory['equipment'],'|', $av_inventory['serial'];?>"></td>

Then

$equipArray =[];
$explodeArray = [];
foreach ($_POST['checkbox'] as $combined) {
  $split = explode('|', $combined);
  $equipArray[] = $split[0];
  $explodeArray[] = $split[1];
}

Then proceed as before.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.