hi people i am making a dynamic form in which the results are shown . the number of results varry every time so they have to be dynamic , if the user clicks on one of the results detials button the user should be redirected to a new page with full detials of the result to make this happen i should know on which result user clicked so i must retive that data. i have used multiple things like using GET but it only gets me the last result values, if i store them in a array how to i know which index of the array is to be used ??? i hope u people can help me out
here is the code i wrote about the form may be there is some mistake in this ..kindly help me out

while($row = mysql_fetch_row($done))
    { 
    ?>
    <form name="RESULT" action="get.php" method="POST" >
    CELL ID
      <input type="text" name="cellid" value="<?php echo $row[0]?>"/>
      <label>DEGRADED KPI:
<input type="text" name="degradedkpi" value="<?php echo $row[1]?>" />
</label>
 
<label>DEGRADED KPI VALUE :
<input type="text" name="degradedkpivalue" value="<?php echo $row[2]?>"/>
</label>
    
<label>REGION
<input type="text" name="region" value="<?php echo $row[3]?>"/>

    
     <label>STATUS
<input type="text" name="status" value="<?php echo $row[4]?>"/>
</label>
<label>
<input type="submit" name="Submit" value="Submit" />
</label>
    <p></p>
    <p></p> 
    <?php

Dani AI

Generated

Quick summary of the core issues raised by the thread: the loop in your code needs a matching closing brace (as noted), and you should avoid relying on multiple identical form fields across rows. As suggested, you only need a way to identify which row was clicked — you do not have to send every column back from the list page. The most robust solution is to pass a single identifier (the row primary key) and load the full row on the details page.

Recommended approach (most secure and maintainable)

  • Emit a link or a tiny form button per result that sends a single ID to the details page.
  • On the details page, validate and sanitize the incoming ID, then perform a prepared query to retrieve all fields for that ID. This avoids long query strings, duplicated inputs, and out-of-sync data.
  • Use PDO or mysqli with prepared statements (do not use the old mysql_* extension).

Example server-side pattern for the details page (validate, then fetch with a prepared statement):

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

$pdo = new PDO('mysql:host=localhost;dbname=yourdb;charset=utf8mb4', 'user', 'pass', [
  PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
]);

$stmt = $pdo->prepare('SELECT first_name, last_name, region, status FROM items WHERE id = ?');
$stmt->execute([$id]);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$row) { exit('Not found'); }

/* escape output before printing */
echo htmlspecialchars($row['first_name']);
?>

Alternatives if you must POST multiple fields from the list page

  • Use hidden inputs per row and submit only the chosen row’s form.
  • Or use a single form with radio buttons or a per-row submit button whose value contains the index or id; the submitted value tells the server which array index to use.

Security/compatibility notes

  • Sanitize and validate every incoming value (use filter_input).
  • Escape output with htmlspecialchars to avoid XSS.
  • Move away from mysql_*; use PDO or mysqli. See PDO docs for examples: https://www.php.net/manual/en/book.pdo.php

Fix the missing brace in your loop, use a single stable identifier per row, and fetch the rest on the detail page — that will solve the array/index confusion and scale cleanly.

Recommended Answers

All 3 Replies

Hey just by the look at your code is no } on your while statement .I need a bit more code if that is possible to help

Hi there,
For one, some browsers will have a problem with multiple forms with the same name, I would go with the $_GET route. Instead of outputting the data in forms like you have done, just display the results normally and where you currently have your submit button, replace it with a link as follows:

<a href="get.php?id=<? echo $row[0] ?>">View All Details</a>

Or of you want a button:

<input type="button" onclick="window.location = 'get.php?id=<? echo $row[0] ?>'" value="View All Details">

Hi there,
For one, some browsers will have a problem with multiple forms with the same name, I would go with the $_GET route. Instead of outputting the data in forms like you have done, just display the results normally and where you currently have your submit button, replace it with a link as follows:

<a href="get.php?id=<? echo $row[0] ?>">View All Details</a>

Or of you want a button:

<input type="button" onclick="window.location = 'get.php?id=<? echo $row[0] ?>'" value="View All Details">

thx buddy your this solution atleast stores first value of the form but the issue is i want to take more than one value from that form suppose $row[0] represents first name , $row[1] represents last name etc so can u help me in this regard ??

and if the values are being stored how to take these values , i mean i have to run a query with the help of this data so i need them , so please help me out !

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.