Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将隐藏变量从一个页面发送到另一个页面_Php_Html - Fatal编程技术网

Php 将隐藏变量从一个页面发送到另一个页面

Php 将隐藏变量从一个页面发送到另一个页面,php,html,Php,Html,我有一个登录脚本,在我的主页上,我的登录表单也在我的主页上。当用户提交表单登录时,他/她提交其用户名和密码 脚本访问的数据库具有用户注册中存储的用户名、密码和电子邮件地址 一旦用户成功登录,他/她将被重定向到一个页面,该页面将加载他们以前在该页面上的评论,这些评论存储在同一数据库的不同表中 我需要将电子邮件从一个表发送到重定向页面上的查询 以下是处理登录的PHP代码的代码: <?php //If the user has submitted the form if(isset($_REQ

我有一个登录脚本,在我的主页上,我的登录表单也在我的主页上。当用户提交表单登录时,他/她提交其用户名和密码

脚本访问的数据库具有用户注册中存储的用户名、密码和电子邮件地址

一旦用户成功登录,他/她将被重定向到一个页面,该页面将加载他们以前在该页面上的评论,这些评论存储在同一数据库的不同表中

我需要将电子邮件从一个表发送到重定向页面上的查询

以下是处理登录的PHP代码的代码:

<?php

//If the user has submitted the form
if(isset($_REQUEST['username'])){
    //protect the posted value then store them to variables
    $username = protect($_POST['username']);
    $password = protect($_POST['password']);

    //Check if the username or password boxes were not filled in
    if(!$username || !$password){
        //if not display an error message
        echo "<center>You need to fill in a <b>Username</b> and a <b>Password</b>!</center>";
    }else{
        //if they were continue checking

        //select all rows from the table where the username matches the one entered by the user
        $res = mysql_query("SELECT * FROM `users` WHERE `username` = '".$username."'");
        $num = mysql_num_rows($res);

        //check if there was no match
        if($num == 0){
            //if none, display an error message
            echo "<center>The <b>Username</b> you supplied does not exist!</center>";
        }else{
            //if there was a match continue checking

            //select all rows where the username and password match the ones submitted by the user
            $res = mysql_query("SELECT * FROM `users` WHERE `username` = '".$username."' AND `password` = '".$password."'");
            $num = mysql_num_rows($res);

            //check if there was no match
            if($num == 0){
                //if none display error message
                echo "<center>The <b>Password</b> you supplied does not match the one for that username!</center>";
            }else{
                //if there was continue checking

                //split all fields from the correct row into an associative array
                $row = mysql_fetch_assoc($res);

                //check to see if the user has not activated their account yet
                if($row['active'] != 1){
                    //if not display error message
                    echo "<center>You have not yet <b>Activated</b> your account!</center>";
                }else{
                    //if they have log them in

                    //set the login session storing there id - we use this to see if they are logged in or not
                    $_SESSION['uid'] = $row['id'];


                    //update the online field to 50 seconds into the future
                    $time = date('U')+50;
                    mysql_query("UPDATE `users` SET `online` = '".$time."' WHERE `id` = '".$_SESSION['uid']."'");

                    //redirect them to the usersonline page
                    echo 'REDIRECT';

                }
            }
        }
    }

    exit;
}

?>
以下是重新定向到页面上的PHP代码:

<?php
  $con=mysqli_connect("","","","");
  // Check connection
  if (mysqli_connect_errno())
  {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
  $result = mysqli_query($con,"SELECT * FROM comments
    WHERE email='$_POST[email]' ORDER BY dt");

  while($row = mysqli_fetch_array($result))
  {
    echo $row['dt'] ." " . $row['email'] . " " . $row['body'];
    echo "<br>";
    echo "<br>";
  }
?>
我需要在第一个代码中添加一些内容,以便从用于验证登录信息的表中提取电子邮件地址,并将其发送到第二个代码以接收评论。我试着用谷歌搜索一个答案,结果一无所获。请帮忙

由于您在代码中使用了$\u会话数组,该数组可能是从某处复制的,因此您可以类似地将电子邮件地址存储在同一数组中

$_SESSION['email'] = $row['email'];

在后面的页面中,您需要将$\u POST['email']替换为$\u SESSION['email']。

我将此代码放入处理登录信息的脚本中。评论仍然不会出现在登录屏幕中。我把代码放错位置了吗?你重定向代码中的email='$\u POST[email]'也需要$\u会话而不是$\u POST