简体   繁体   中英

Result of a PHP & MySQL query with hyperlink

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?

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

$emp_id = $_GET['emp_id'];

should be:

$emp_id = $_GET['id'];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM