Hi,
I've had this problem for the last few months and I thought I'd found a solution but unfortunately not. I've stripped it down to its bare bones to have a look.
The code below displays the 3 records in the db table with a standard select and while loop. I need to be able to update each row independently so I added a submit button and enclosed it all in a form.
<?php
// connect to db
$req_comm = $_POST['reqcomm'];
if ($_POST['authbox']) {
$auth_array = isset($_POST['authbox']) && is_array($_POST['authbox'])? $_POST['authbox']: array();
foreach($auth_array as $req_id => $key) {
$query = "UPDATE reqs SET status = 'authorised', reqcomm = '$req_comm' WHERE reqid = '$req_id'";
$result = mysql_query ($query) or die (mysql_error());
}
}
$firstquery = "SELECT * FROM `reqs` WHERE `username` = 'test' AND `status` = 'pending' ";
$first = mysql_query($firstquery) or die(mysql_error());
?>
<hr>
<form method="POST" action="">
<?php
while ($row = mysql_fetch_array($first)) { // START WHILE
$req_id = $row[0]; $req_comm = $row[17];
?>
<table>
<tr align='left'>
<td><?php echo $req_id;?></td>
<td><input type="submit" name="authbox[<?php echo $req_id; ?>]" value="Send"></td>
<td><input type ="text" size="20" name="reqcomm" value="<?php echo $req_comm; ?>"></td>
</tr>
</table>
<?php }; ?> // END WHILE
<hr>
</form> <!-- end form tag here - but only sends $req_comm on the bottom row of whats displayed? -->
//////////////////////////////////////////////////////
The above displays the 3 records:
Reqid 55 | Send | input box
Reqid 60 | Send | input box
Reqid 65 | Send | input box
And heres the problem:
If I fill in the reqcomm input field on Reqid 65 and click Send, it all works, reqcomm is picked up by the post superglobal and used in the update statement but if I try to do it on Reqid 55 or 60 it doesn't, the reqcomm field in the db is not updated and I need it to work irrespective of which req is sent first?
What I'm trying to do seems simple but I've tried swapping and moving everything around and tried posting an array instead of just name="reqcomm" but I can't get it working.
I'm wondering if it's something more serious, something to do with the whole structure lay out?
Any help or pointers would be great as I really haven't got a clue whats happening here or what else to try?