Passing session between pages

时间:2017-11-14 23:50:27

标签: php node.js

here is my requirement. I wanted to pass a variable from one html to another html both has php in it. I know the logic is pretty bad. On clicking the button meant for $row['Room_ID'], it needs to go to plugload6.php . In that php, I wanted to get the Room_ID and handle that in a query. As far as I know, I should do this with onclick listener which calls JS file. In JS file, I should create a session and call the php file. Could you please help me in achieving the same.Please find the code below Main.html:

if(mysqli_num_rows($result)>0)
{
    while($row=mysqli_fetch_assoc($result))
    {
        //$variable=$row['Room_ID'];
        $_SESSION['myVar']=$row['Room_ID'];
        //echo $row['Room_ID']; 
        $newval=$_SESSION['myVar'];
        echo $newval;  
        echo "<tr style='border-bottom: ridge;'>";

        echo "<td align='center'>";
        echo "<a class=".$row['Room_ID']." onclick='plugButton(Room_ID)' href='plugload6.php' class='action-button shadow animate blue' style='color: rgb(255,255,255)'>".$row['Room_ID']."</a>";
        echo "<td>";
        echo "<a href='plugload6.php' class='action-button shadow animate  blue' style='color: rgb(255,255,255)'>".$row['Room_ID']."</a>"; 
        echo "</td>";

plugload6.php:

<?php
//connecting to SQL database plug to retrieve the list of plugs
$room=$_SESSION['myVar'];
echo $room;

$conn=mysqli_connect("localhost","root","") or die("failed");
$db=mysqli_select_db($conn,"splug");
$result=mysqli_query($conn,"select Plug_ID from plug where       Room_ID='".$room."'") or die("failed to connect database".mysql_error());
//$row=mysqli_fetch_array($result);
//count=1;

I wanted to handle in the form of session which can make my life easier. Please guide me in completing the same.

1 个答案:

答案 0 :(得分:0)

确保您使用echo "<a href='plugload6.php?roomId=".$row['Room_ID']."' class='action-button shadow animate blue' style='color: rgb(255,255,255)'>".$row['Room_ID']."</a>"; 开始了会话。

或者不使用PHP会话而是将URL末尾的Room_ID作为GET参数传递

$room = $_GET['roomId'];

而不是在plugload6.php中使用

EmployeeId

获取房间ID。