<?php
require('db.php');
include("auth.php");
$id=$_REQUEST['id'];
$query = "SELECT * from new_record where id='".$id."'"; 
$result = mysqli_query($con, $query) or die ( mysqli_error());
$row = mysqli_fetch_assoc($result);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>View Records</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<div class="form">
<p align='center'><a href="index.php">Home</a> | <a href="view.php">View Account</a> | <a href="logout.php">Logout</a></p>
<hr>
<p align='center'><font size='5'>Business Name Here</font></p>
<p align='center'><font size ='2'>Display Address here</font></p>
<p align='center'><font size ='2'>Contact Number here</font></p>
<hr>
    <table width="100%" border="1" style="border-collapse:collapse;">
    <thead>
    <tr><th><strong>Accnt No</strong>
    </th><th><strong>Name</strong>
    </th><th><strong>Address</strong></th>
    </th><th><strong>Contact No</strong></th>
    </th><th><strong>Loan Amount</strong></th>
    </th><th><strong>Loan Date</strong></th>
    </th><th><strong>Interest Rate</strong></th>
    </tr>
    </thead>
<tbody>
<?php
$count=0;
$sel_query="SELECT * from new_record where id='".$id."'";
$result = mysqli_query($con,$sel_query);
while($row = mysqli_fetch_assoc($result)) { ?>
<tr><td align="center"><?php echo $count; ?>
</td><td align="center"><?php echo $row["name"]; ?>
</td><td align="center"><?php echo $row["address"]; ?>
</td><td align="center"><?php echo $row["contact_no"]; ?>
</td><td align="center"><?php echo $row["loan_amount"]; ?>
</td><td align="center"><?php echo $row["loan_date"]; ?>
</td><td align="center"><?php echo $row["interest_rate"]; ?>
<?php $count++; } ?>
</tbody>
</body>
</html>

Dani AI

Generated

— the symptom is intentional in the posted template: the table cell for "Accnt No" is echoing the counter variable ($count) which is initialized to 0 and only incremented after the echo. That will always show 0 for the first/only row. Also follow 's hint: confirm the id parameter is actually arriving (the link must look like view.php?id=123).

Practical fixes (pick what fits intent)

  • To show the database id (account number) print the DB field: echo htmlspecialchars($row['id']);.
  • To show a serial row number increment before printing: echo ++$count; or initialize count = 1 and use echo $count++;.
  • If the column name is different, use the actual column name returned by the query. Use var_dump(array_keys($row)) while debugging to see available fields.
  • Replace $_REQUEST with $_GET (or $_POST) and validate: filter_input(INPUT_GET,'id',FILTER_VALIDATE_INT). Avoid SELECT * and avoid injecting $id directly into SQL.

Minimal, safer example (focus on fetching the id only):

<?php
$id = filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT);
if (!$id) exit('Invalid id');

$stmt = $con->prepare('SELECT id FROM new_record WHERE id = ?');
$stmt->bind_param('i', $id);
$stmt->execute();
$res = $stmt->get_result();
if ($row = $res->fetch_assoc()) {
    echo '<td align="center">' . htmlspecialchars($row['id']) . '</td>';
} else {
    echo '<tr><td colspan="7">Record not found</td></tr>';
}

Extra troubleshooting tips

  • Temporarily enable errors: error_reporting(E_ALL); ini_set('display_errors',1);.
  • If using mysqli_query(... ) or die(mysqli_error()) pass the connection: mysqli_error($con).
  • Inspect the link that opens the page (ensure ?id=... is present).
  • Keep HTML tags balanced (</td>, </tr>, </tbody>) — malformed markup can hide output.

Recommended Answers

All 2 Replies

i can view name, address, contact No, Loan Amount, Loan Date and Interest Rate correctly the only problem is the ID

are you passing the id variable in the link to the page? When you do a $_REQUEST['id'] its looking for ?id=1 or ?id=testuser in the link from the previous page.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.