Hi,
I've got a strange one here, usually when something doesn't work it always doesn't work so I can try breaking it down to have a look but here it only doesn't work with one scenario.
The code below displays 2 rows which are retrieved from the sql db via the initial page selection query. And heres where it goes strange.
First Scenario
2 rows are displayed
I input into the top row and the UPDATE statement doesn't work and the variables are not echoed to screen. But if I carry on and input into the second row it does work.
Second Scenario
2 rows are displayed
I input into the second row first and everything works and I carry on and input into the first row and everything works.
So the problem is only when I try the top row first as in first scenario?
I've put this issue into the test script below:
<?php
// connect to db
// posted varaiables
$gdsinno = $_POST['gdsinno'];
$suppref = $_POST['suppref'];
$gdsinreason = $_POST['gdsinreason'];
// PROBLEM does'nt work first time but does second?
if ($_POST['authbox']) {
$auth_array = isset($_POST['authbox']) && is_array($_POST['authbox'])? $_POST['authbox']: array();
foreach($auth_array as $reqid => $key) {
$gdquery = "UPDATE gdsin SET gdsinno = '$gdsinno', gireason = '$gdsinreason', suppref = '$suppref' WHERE reqid = '$reqid'";
$gdresult = mysql_query ($gdquery) or die (mysql_error());
}
}
?>
<hr>
<font color='#000'><?php
// For debugging
echo $reqid; echo $username; echo $gdsinno; echo $suppref; echo $gdsinreason; ?>
</font>
<form method="POST" action="postupdate.php">
<?php
// initial page selection
$firstquery = "SELECT * FROM `gdsin` WHERE `username` = 'test' AND `gdsinstatus` = 'expected' ";
$first = mysql_query($firstquery) or die(mysql_error());
while ($row = mysql_fetch_row($first)) {
$gdsinid = $row[0]; $reqid = $row[1]; $gdsinno = $row[7]; $gdsinreason = $row[8]; $suppref = $row[9];
?>
<font color="#blue">Req ID:<?php echo $reqid;?></font>
Gds In<input type ='text' class='input' size='18' name='gdsinno' value=''>
Supp Ref<input type ='text' class='input' size='18' name='suppref' value=''>
GD Reason<input type ='text' class='input' size='80' name='gdsinreason' value=''>
<input type="submit" class="buttonauth" name="authbox[<?php echo $reqid; ?>]" value="Submit">
<br>
<?php }; ?>
</form>
Any help would be much appreciated.