Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/67.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_Mysql_Session - Fatal编程技术网

Php 无法将唯一会话值从一个页面传输到另一个页面

Php 无法将唯一会话值从一个页面传输到另一个页面,php,mysql,session,Php,Mysql,Session,我已经创建了一个应用程序,我想将唯一值/id从一个页面传输到另一个页面。我已将会话用于此过程 以下代码: <?php session_start();?> <?php #php code to get values include_once "process/config.php"; $sql = "select * from posts"; static $i=0; $result = mysqli_query($conn,$sql); if($result->n

我已经创建了一个应用程序,我想将唯一值/id从一个页面传输到另一个页面。我已将会话用于此过程

以下代码:

<?php session_start();?>
   <?php
#php code to get values
include_once "process/config.php";
$sql = "select * from posts";
static $i=0;
$result = mysqli_query($conn,$sql);
if($result->num_rows > 0){
while($rows = $result->fetch_assoc()){  
$_SESSION["post_row_id"] = $rows["id"]; #Storing post id for updation.
echo $_SESSION["post_row_id"];
?>         

        <tr class="gradeA">
            <td><?php echo ++$i; ?></td>

    <td><u><a onmouseover="this.style.color='blue'" onmouseout="this.style.color='black'" href="post_action.php">
    <?php echo $rows["post_title"]; ?></a></u></td>

        </tr>                                       
  <?php
    }

}
?>   

我想用$\u SESSION[“post\u row\u id”]将行id传输到post\u action.php页面,但每次单击锚定标记时,最后一个id都会传输到下一页。 但是当我回显$\u SESSION[“post\u row\u id”]时,会显示所有唯一的值

注意
我是通过在锚定标签中传递id来完成的,工作正常。但是在URL中显示了该值,任何人都可以更改该值并传递一些其他数据。会话在这一点上是安全的,因此我尝试使用会话来执行此操作。

根据您的要求,您需要传递当前行唯一id,因此使用
GET方法像这样使用它。
出于安全目的,请在服务器端验证它。

<a href="post_action.php?row_id=<?php echo $rows["id"]; ?>"<?php echo $rows["post_title"]; ?></a>


注意:您可以在会话中存储所有id。但是您找不到单击@jasshandrews的行。根据您的要求,您需要传递当前行的唯一id,因此使用
GET方法像这样使用它。
出于安全目的,请在服务器端验证它。

<a href="post_action.php?row_id=<?php echo $rows["id"]; ?>"<?php echo $rows["post_title"]; ?></a>
To stick with your original code,
you can pass parameters on your <a href> tag, 
by adding something like this to your url,

<a href="post_action.php?rows_id=$rows_id"></a>

 if your goal is just to pass that id to another page,  you may remove the session since its no longer needed since the id is already passed on your url,


<?php session_start();?>
           <?php
        #php code to get values
        include_once "process/config.php";
        $sql = "select * from posts";
        static $i=0;
        $result = mysqli_query($conn,$sql);
        if($result->num_rows > 0){
        while($rows = $result->fetch_assoc()){  
        $_SESSION["post_row_id"] = $rows["id"]; #Storing post id for updation.
        echo $_SESSION["post_row_id"];
        ?>         

                <tr class="gradeA">
                    <td><?php echo ++$i; ?></td>

            <td><u><a onmouseover="this.style.color='blue'" onmouseout="this.style.color='black'" href="post_action.php">
            <?php echo $rows["post_title"]; ?></a></u></td>

                </tr>                                       
          <?php
            }

        }
        ?>   

注意:您可以在会话中存储所有id。但是您找不到单击@jasshandrews以保留原始代码的行,
To stick with your original code,
you can pass parameters on your <a href> tag, 
by adding something like this to your url,

<a href="post_action.php?rows_id=$rows_id"></a>

 if your goal is just to pass that id to another page,  you may remove the session since its no longer needed since the id is already passed on your url,


<?php session_start();?>
           <?php
        #php code to get values
        include_once "process/config.php";
        $sql = "select * from posts";
        static $i=0;
        $result = mysqli_query($conn,$sql);
        if($result->num_rows > 0){
        while($rows = $result->fetch_assoc()){  
        $_SESSION["post_row_id"] = $rows["id"]; #Storing post id for updation.
        echo $_SESSION["post_row_id"];
        ?>         

                <tr class="gradeA">
                    <td><?php echo ++$i; ?></td>

            <td><u><a onmouseover="this.style.color='blue'" onmouseout="this.style.color='black'" href="post_action.php">
            <?php echo $rows["post_title"]; ?></a></u></td>

                </tr>                                       
          <?php
            }

        }
        ?>   
您可以在您的计算机上传递参数 如果您的目标只是将该id传递到另一个页面,您可以删除该会话,因为它不再需要,因为该id已在您的url上传递,
要坚持原来的代码,
您可以在您的计算机上传递参数
如果您的目标只是将该id传递到另一个页面,您可以删除该会话,因为它不再需要,因为该id已在您的url上传递,

1。您需要添加
session_start()
在顶部的每个页面上,您将处理
会话
href=“post_action.php?row_id=“@AlivetoDie:我已经添加了那行代码。@JYoThI:我想使用会话变量。@jashhandrews-我认为按照您的要求,会话不应该工作。您需要做的是使用post请求或get请求。但在提交页面上,出于安全原因,您可以验证Id。1。您需要添加
session_start()
在顶部的每个页面上,您将处理
会话
href=“post_action.php?row_id=“@AlivetoDie:我已经添加了那行代码。@JYoThI:我想使用会话变量。@jashhandrews-我认为按照您的要求,会话不应该工作。您需要做的是使用post请求或get请求。但在提交页面上,出于安全原因,您可以验证Id。