【发布时间】:2019-10-16 09:03:48
【问题描述】:
我目前正在阅读我的教师提供的一段代码,但我无法理解它的工作原理。 具体来说,锚是如何在没有 method="post" 或 method="get" 的情况下链接到 php 的。 如果有人可以解释或将我链接到相关材料以进行进一步阅读,请不胜感激。非常感谢。
if (!isset($_SESSION['cart'])){
$_SESSION['cart'] = array();
}
if (isset($_GET['buy'])) {
$_SESSION['cart'][] = $_GET['buy'];
header('location: ' . $_SERVER['PHP_SELF']. '?' . SID);
exit();
}
for ($i=0; $i<count($items); $i++){
echo "<tr>";
echo "<td>" .$items[$i]. "</td>";
echo "<td>$" .number_format($prices[$i], 2). "</td>";
echo "<td><a href='" .$_SERVER['PHP_SELF']. '?buy=' .$i. "'>Buy</a></td>";
echo "</tr>";
}
【问题讨论】:
-
href-?buy=中的查询字符串变量-可以用$_GET['buy']提取。
标签: javascript php html sql