[英]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.我希望能够多次提交并将数据存储在 session 数组中,以便在其他服务器页面中访问。 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>
In Lab5-2.php
you need to store like that:在
Lab5-2.php
,您需要这样存储:
session_start();
$postvariable=$_POST['customer'];
$_SESSION['customer']=$postvariable;
Obv for prevent Sql Attack use that guide用于防止 Sql 攻击的 Obv 使用该指南
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"所以例如你有插入产品值“pc”,然后下次更新有“mouse”,你将有“pc,mouse”
Try something like this尝试这样的事情
session_start();
$_SESSION['data'][] = $_POST;
This should store all the $_POST
data inside the session.这应该将所有
$_POST
数据存储在 session 中。
Use print_r($_SESSION['data']);
使用
print_r($_SESSION['data']);
to check if the data is appending to the session.检查数据是否附加到 session。 This should do exactly what you are looking for.
这应该完全符合您的要求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.