gpt4 book ai didi

php - 两个 php 表单。第二种形式从第一种形式获取数据。但刷新第二页显示错误

转载 作者:行者123 更新时间:2023-11-29 16:05:12 24 4
gpt4 key购买 nike

我正在显示数据库中的设备信息列表。每个设备都会有一个“显示警告”按钮。用户可以单击“显示警告”,我正在使用隐藏字段(隐藏字段中的值来识别)来显示设备警告消息。来自数据库的每个警告都有一个接受按钮(每个警告都有接受按钮)。用户可以单击“接受”按钮,使警告的状态从“不接受”变为“接受”(并且页面将刷新)。问题出在刷新上,因为它没有来自第一页的信息,php 返回错误。

//page-1.. under each category (like electrical, mechanical, more than one types of devices
//device can be identified by using ID


echo '<tr><th>Category Name</th>';
echo '<td >' . $row['category']. '</td></tr>';

echo '<tr><th>Device ID</th>';
echo '<td >' . $row['ID']. '</td></tr>';

//form section.

echo "<form action = alarms_list_display.php method =post>";
echo '<tr>';

echo "<td >"." <input type=submit name=acceptID value=ShowAlarm"." </td>";
echo "<td >"." <input type=hidden name=hiddenID value =". $row["ID"]." </td>";
echo "</tr>";
echo "</form>";


//second page..    alarms_list_display.php

include ("DBconnect.php");
$conn= mysqli_connect( $dbhost, $dbuser, $dbpass, $db );

if(isset($_POST ['acceptID']))
{$deviceID = $_POST['hiddenID'];

}
else {$deviceID='';}


//above code is problematic. as it is available only when i submit the first page.
//when updating the second page (and refreshing), $deviceID is not available anymore.



//listing all warnings related to that device when user clicked the 'ShowAlarm' button.

if ($conn->connect_error) {die("Connection failed: " . $conn->connect_error);}
$sql = "SELECT * FROM dataTable WHERE ID='$deviceID' ";
$result = $conn->query($sql);

//form with buttons to accept warning
//skipped table heading parts
//each warning will have a serialNumber. Using to accept the warning and update the database

if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo "<form action = alarms_list_display_copy.php method =get>";


echo "<td>" . $row["Date"]. "</td>";
echo "<td>" . $row["Warning"]. "</td>";

echo "<td>"." <input type=hidden name=hidden value =" .$row["SerialNumber"]." </td>";
echo "<td>"." <input type=submit name=accept value=AcceptAlarm id=button1 class = formclass"." </td>";
echo "</tr>";

echo "</form>";
} else { echo "0 results"; }



//code to update when clicking the AcceptAlarm button.

if (isset($_GET['accept'])){
$query= "SELECT WarningAccept FROM dataTable WHERE SerialNumber= '$_GET[hidden]' ";
$result = mysqli_query($conn, $query);
while($row = $result->fetch_assoc()) {

$updateQuery = " UPDATE dataTable SET WarningAccept=1 WHERE SerialNumber= '$_GET[hidden]' ";
mysqli_query($conn, $updateQuery);

}


可以提交首页。它将显示与该设备对应的所有警告。但是当接受警告时,页面将刷新并且 $deviceID 不再存在。所以更新后不会显示任何警告消息。怎么改呢???任何帮助

最佳答案

您的second page只获取一次值 <form action = alarms_list_display.php method =post>";已提交,这就是刷新第二页时出现错误的原因,因为它丢失了 $_POST然后数组

解决方案

您可以设置<form action = alarms_list_display.php method =post>"的 Action 到同一页面并在 session 中存储值,然后将其重定向到第二页,然后您可以使用 session 中的值

关于php - 两个 php 表单。第二种形式从第一种形式获取数据。但刷新第二页显示错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55809858/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com