【问题标题】:Result of a PHP & MySQL query with hyperlink带有超链接的 PHP 和 MySQL 查询的结果
【发布时间】:2016-06-22 09:47:06
【问题描述】:

我创建了 2 个 php 文件。其中一个(sql_hyperlink.php)是一种表单,它接受输入并显示带有员工 ID 的记录列表作为超链接。下一个文件 (employee.php) 将在单击超链接时显示员工的详细信息。

第一部分工作正常,下一页以正确的 url id 打开,但不知何故,变量 emp_id 没有保留该值。 Employee.php 没有显示任何东西! 我已经阅读了几个类似的主题并尝试了各种方法,但遗漏了一些东西。

我的代码是: 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>

如果我在行后回显 emp_id

$emp_id = $_GET['emp_id'];

它不显示id。

谁能帮我解决这个问题?

【问题讨论】:

  • 在您的 URL 中,您将 id 分配给获取参数名称“id”,但假设它在您的代码中是 emp_id。

标签: php mysql hyperlink


【解决方案1】:

您在链接?id='.$emp_id.' 中提供参数id 名称:

$emp_id = $_GET['emp_id'];

应该是:

$emp_id = $_GET['id'];

【讨论】:

  • 嗨 Gouda,非常感谢您的回答.. 它的工作... :)
猜你喜欢
  • 2012-05-24
  • 2012-04-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-19
  • 1970-01-01
相关资源
最近更新 更多