Skip to content
Advertisement

How do I store multiple similar data in a session array in PHP?

I would like to be able to submit multiple times and store the data in a session array to be accessed in other server pages. I’n not sure how to do it.

<form action="Lab5-2.php" method="post">
<table>
    <tr>
      <td align="center"><b>Customer Code</b></td>
      <td align="center"><b>Product Code</b></td>
      <td align="center"><b>Quantity</b></td>
    </tr>
    <tr>
      <td align="left"><input type="text" name="customer" required autocomplete="off"></td>
      <td align="right"><input type="text" name="product" required autocomplete="off"></td>
      <td align="right"><input type="text" name="quantity" required autocomplete="off"></td>
      <td align="right"><input type="submit" value="Submit" style="width: 80px"></td>
    </tr>
  </table>
</form>

Advertisement

Answer

In Lab5-2.php you need to store like that:

session_start();
$postvariable=$_POST['customer'];
$_SESSION['customer']=$postvariable;

Obv for prevent Sql Attack use that guide

For you question on comment you can do that:

session_start();
$postvariable=$_POST['customer'];
$_SESSION['customer']=$_SESSION['customer'].','.$postvariable;

So for example you have insert product value “pc”, then update next time have “mouse”, you will have “pc,mouse”

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement