我正在研究我的学期项目,我想在下一页(order.php)中传递变量“ value”。它是从基于数据库填充的另一个下拉框的下拉框检索的值。我已经确认该值已存储,但无法在下一页检索它。
我尝试了localstorage(转NULL),会话变量(未定义的索引“值”)并将其放入url,但似乎没有任何效果,并且非常令人沮丧。有人可以帮我举个例子吗?谢谢
session_start();
$conn = new mysqli("localhost", "root", "", "restaurant_ordering");
mysqli_set_charset($conn,"utf8mb4");
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "select * from sector ";
$result = $conn->query($sql);
while($row = $result->fetch_assoc()){
$categories[] = array("id" => $row['id'], "val" => $row['name']);
}
$sql = "SELECT * FROM booth";
$result = $conn->query($sql);
while($row = $result->fetch_assoc()){
$subcats[$row['sector_id']][] = array("id" => $row['id'], "val" => $row['name']);
}
$jsonCats = json_encode($categories);
$jsonSubCats = json_encode($subcats);
?>
<!doctype html>
<html>
<head>
<script type='text/javascript'>
<?php
echo "var categories = $jsonCats; \n";
echo "var subcats = $jsonSubCats; \n";
?>
function loadCategories(){
var select = document.getElementById("categoriesSelect");
select.onchange = updateSubCats;
for(var i = 0; i < categories.length; i++){
select.options[i] = new Option(categories[i].val,categories[i].id);
}
}
function updateSubCats(){
var catSelect = this;
var catid = this.value;
var subcatSelect = document.getElementById("subcatsSelect");
subcatSelect.options.length = 0;
for(var i = 0; i < subcats[catid].length; i++){
subcatSelect.options[i] = new Option(subcats[catid][i].val,subcats[catid][i].id);
}
}
function handleSelectChange(event) {
var selectElement = event.target;
var value = selectElement.value;
}
</script>
<meta charset="utf-8">
<title>New Order</title>
<link rel="stylesheet" href="server.css" />
</head>
<body onload='loadCategories()'>
<p><a href="server.html"style="color:#ffcc00">Home</a>
| <a href="../login.html"style="color:#ffcc00">Logout</a></p>
<h2>New Order</h2>
<strong>Sector:</strong>
<form name="form" method="post" action="order.php" >
<select id='categoriesSelect'>
</select>
<select id='subcatsSelect' onchange="handleSelectChange(event)">
</select>
<input type="hidden" name="new" value="1" />
<input type="hidden" name="select" id="total" value="">
</div>
</div>
<div id="button">
<p><input name="submit" type="submit" value="Submit" onclick= </p>
</div>
</form>
</body>
</html>```
答案 0 :(得分:2)
已提交表单中的表单值将在“ order.php”中的$_POST
变量中提供。通过使用想要输入值的表单输入的HTML“名称”属性来查找值。因此,如果您想要隐藏的“新”表单元素的值,请使用$_POST['new']
在“ order.php”中获取值。
答案 1 :(得分:1)
好吧,如果我知道您想从第一个php页面获取价值并传递到另一个php页面。 因此,只需在第一个PHP中完成 做
$ _ SESSION ['神话'] = $ value_that_want_pass;
在第二个php页面上 做
session_start();
echo $ _SESSION ['mything'];