0

我想运行这个脚本来更新数据库,然后检查它是否确实更新了,然后设置一个变量这样说并重定向回上一页并回显该页面上的成功更新或不成功更新。目前它运行完美,但不会回显成功或不成功的部分。我能做些什么来解决这个问题?

<?php
include_once('../../../_php/connect.php');

$update_e_id = $_POST['error_id'];

//Update unresolved to resolved
mysql_query("UPDATE error SET resolution='resolved' WHERE id=" . $update_e_id . " 
AND resolution='unresolved'");

//Check if it updated
$checkE_update = "SELECT * FROM error WHERE id=" . $update_e_id . " AND 
 resolution='resolved'";
$results = mysql_query($checkE_update);
$nr = mysql_num_rows($results);

while($row = mysql_fetch_assoc($results)) {
    $checkResolution = $row['resolution'];
}
if($checkResolution = 'resolved') {
    $successfullyUpdated = "<p>The error is now resolved.</p>";
    header("Location: ../lib_errors.php");
}   else {
        $didnotUpdateError = "<p>The update was unsuccessful.</p>";
        header("Location: ../lib_errors.php");
    }
 ?>
4

4 回答 4

0

其他答案中提到的$_SESSION方法是一种方法。另一种可能是将有关成功或不成功的消息存储在一个$_GET变量中,并将它们传递到被调用的 URI 中:

// ...
if($checkResolution = 'resolved') {
    $status = 'success';
    $message = "<p>The error is now resolved.</p>";
} else {
    $status = 'error;
    $message = "<p>The update was unsuccessful.</p>";
}
$uri = '../lib_errors.php?status='.$status.'&message='.$message;
header('Location: '.$uri);

然后在你的lib_errors.php你可以使用:

$status  = $_GET['status'];
$message = $_GET['message'];
于 2013-09-14T18:15:25.213 回答
0
if($checkResolution = 'resolved') {
    $successfullyUpdated = "<p>The error is now resolved.</p>";
    header("Location: ../lib_errors.php?msg=The error is now resolved.");
}   else {
        $didnotUpdateError = "<p>The update was unsuccessful.</p>";
        header("Location: ../lib_errors.php?msg=The update was unsuccessful.?msg=");
    }
 ?>

并在您的重定向页面上回显此消息:

<?php echo $_GET['msg']; ?>
于 2013-09-14T18:15:52.387 回答
0

使用会话...确保在每个页面的顶部都有这个 php 标签;

session_start();

然后做

$_SESSION['name'] = $varName;

然后在另一个页面上,您可以回显会话

echo $_SESSION['name'];
于 2013-09-14T18:07:38.503 回答
0

我不知道您为什么再次执行选择查询。从更新查询本身,您将获得成功或失败

//Update unresolved to resolved
$rs = mysql_query("UPDATE error SET resolution='resolved' WHERE id=".$update_e_id." AND resolution='unresolved'");
if($rs) {
    header("Location: ../lib_errors.php?msg=The error is now resolved");
}
else {
    header("Location: ../lib_errors.php?msg=The update was unsuccessful");
}

在 lib_error.php 你会得到你的消息,因为$_GET['msg'];你可以在任何你想要的地方回显它

于 2013-09-14T18:21:17.040 回答