duanmen2189 2016-03-08 12:34
浏览 45
已采纳

带有超链接的PHP和MySQL查询的结果

I have created 2 php files. One (sql_hyperlink.php) is a form which will accept inputs and display a list of records with employee id as a hyperlink. The next file (employee.php) will display the detail of the employee when the hyperlink is clicked.

The first part is working fine and the next page is opening with the correct id in the url, but somehow the variable emp_id is not retaining the value. Employee.php is not displaying anything! I have read several similar topics and tried various ways but missing something.

My codes are: sql_hyperlink.php

<table id = "hyperlinked_table" align="center" border="1" cellpadding="3">
    <tr><th>Employee ID</th><th>Name</th><th>Username</th></tr>
    <?php
        while ($result = mysqli_fetch_assoc($sql)) {
            $emp_id = $result['emp_id'];
            $fname = $result['first_name'];
            $lname = $result['last_name'];
            $uid = $result['username']
    ?>
    <tr> 
        <td> <?php echo '<a href="employees.php?id='.$emp_id.'">'.$emp_id.'</a>'; ?> </td>
        <td><?php echo $fname ?> <?php echo $lname ?> </td>
        <td><?php echo $uid ?> </td>
    </tr>
    <?php

        }
    ?>
</table>

employee.php

<body>
<?php
$emp_id = $_GET['emp_id'];
include 'db_connect.php';
$sql = mysqli_query($connect, "SELECT * FROM user_master WHERE emp_id =    '".$emp_id."'"); 
$result = mysqli_fetch_assoc($sql);
$emp_id = $result['emp_id'];
?>

<div id="mem_photo"></div>

  <table id="mem_details">
    <caption><b>Employee Details</b></caption>
    <tr>
    <td>Employee ID: <?php echo $emp_id ?></td>
    <td>Card Number: <input type="text" name="card_no"></td>
    <td>Employee Status: </td>          
    </tr>

If I echo the emp_id after the line

$emp_id = $_GET['emp_id'];

it does not display the id.

Can anyone please help me with this?

  • 写回答

1条回答 默认 最新

  • dpik71879 2016-03-08 12:36
    关注

    you give your param id name in your link ?id='.$emp_id.' :

    $emp_id = $_GET['emp_id'];
    

    should be:

    $emp_id = $_GET['id'];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算