如果PHP语句没问题,那么请在下一页回答

时间:2015-09-12 08:42:21

标签: php

我想在另一页上显示结果。我有这个代码,结果在同一页面上:

<?php
$con = mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("ims", $con) or die(mysql_error());
$msg          = "";
$verification = "";
$name         = "";
$parent       = "";
$birth        = "";
$regno        = "";
$issue        = "";
if (isset($_POST["search"])) {
    $query = mysql_query("select * from verification where verification='" . $_POST["verification"] . "'");
    $num   = mysql_num_rows($query);
    if ($num > 0) {
        $res          = mysql_fetch_assoc($query);
        $verification = $res["verification"];
        $name         = $res["name"];
        $parent       = $res["parent"];
        $birth        = $res["birth"];
        $regno        = $res["regno"];
        $issue        = $res["issue"];
    } else {
        $msg = "Record not found";
    }
}
?>

如何更改此设置以便结果显示在另一个页面上?

请帮助我。我用这个作为考试成绩。

1 个答案:

答案 0 :(得分:0)

您需要使用PHP会话:http://php.net/manual/en/features.sessions.php

在query.php中:

// Initiate the use of session variables
session_start();
...
do query
...
// Create local storage array
$queryResult = array (
  'verification'=>$res["verification"],
  'name'=>$res["name"],
  'birth'=>$res["birth"],
  'regno'=>$res["regno"],
  'issue'=>$res["issue"]
);
// Transfer local storage to session storage
$_SESSION['queryResult'] = $queryResult;
// Redirect the user
header('Location: http://example.com/result.php');
exit;

然后在result.php中:

// Initiate the use of session variables
session_start();
// Check if the session exists
if (isset($_SESSION['queryResult'])) {
  // Transfer session to local storage
  $queryResult = $_SESSION['queryResult'];
} else {
  printf('Unable to find or access the session information.');
  exit;
}
// Display query result
echo '<pre>';
print_r($queryResult);
echo '</pre>';