mercredi 12 février 2020

How to append new elements to the end of a session in php?

I have a Session where I am storing some IDs and I would like to add to the end of that session a string (attach to its own respective id).

Here I have a table with some elements and I have some checkboxes there so when each checkbox is selected I am taking their ids and when posting I am storing those ids to a session:

    <form method="post">
    <?php if (!empty($arr_devices)) { ?>
        <?php foreach ($arr_devices as $device) : ?>
            <tr>
                <td>
                    <input type="checkbox" name="devices[]" value="<?php echo $device["id"] ?>">
                    <?php echo '<a href=error_report.php?device_id=' . urlencode($device["id"])  . "&dev_name=" . urlencode($device["name"]) . "&imei=" . urlencode($device["serial_imei"]) . "&serial_no=" . urlencode($device["serial_no"]) . "&device_no=" . urlencode($device["device_no"]) .  '>' . $device["name"] . '</a>'; ?>
                </td>

                <td>
                    <?php echo '<a href=error_report.php?device_id=' . urlencode($device["id"]) .  "&dev_name=" . urlencode($device["name"]) . "&imei=" . urlencode($device["serial_imei"]) . "&serial_no=" . urlencode($device["serial_no"]) . "&device_no=" . urlencode($device["device_no"]) .  '>' . $device["device_no"] . '</a>'; ?>
                </td>

                <td>
                    <?php echo '<a href=error_report.php?device_id=' . urlencode($device["id"]) .  "&dev_name=" . urlencode($device["name"]) . "&imei=" . urlencode($device["serial_imei"]) . "&serial_no=" . urlencode($device["serial_no"]) . "&device_no=" . urlencode($device["device_no"]) . '>' . $device["barcode"] . '</a>'; ?>
                </td>

<td>
                        <div class="input-group">
                            <textarea name="dev_comment" placeholder="Write your comment here" rows="1" cols="50"><?php echo $dev_comment; ?></textarea>
                        </div>
                    </td>

            </tr>
    <?php endforeach; ?>
    <?php } ?>
    <input class="btn" type="submit" name="submit" value="Report">
    <form>

Here is the the way I am storing those IDs:

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $_SESSION['devices_id'] = $_POST['devices'];
}

what I would like to do is to add the $dev_comment to that Session. So that when I use that Session I need to have the $dev_comments attached to each respective id. How can I implement that?




Aucun commentaire:

Enregistrer un commentaire