This is my form. I increment the field names as an integer so each is unique when passed through the http post
______________________________________...
<?php
include("connection.php");
mysql_select_db("mytest", $con); // work order
$result_1 = mysql_query("SELECT id, status, dueby, priority, whogets, stmtsteam, livefiledt, holdfile, heldfile, feeamt, needappr, taxid, login, practname, billtoname, billtoacctnum, billingkey, software, contact, reseller, phnum, email, shortissue, issue, resolution, datecompleted, completedby, contactedclient, contactedby, contactvia, indate, ptstmtdt_1, ptacctnum_1, ptname_1, uniquenum_1, ptstmtdt_2, ptacctnum_2, ptname_2, uniquenum_2, ptstmtdt_3, ptacctnum_3, ptname_3, uniquenum_3 FROM bunk3 where status != 'closed'");
if (!$result_1) {
echo 'Could not run query: ' . mysql_error();
exit;
}
?>
<form ACTION="test_print.php" METHOD = POST>
<?php
$myint = 0;
echo "<table border = '1' >";
while($row = mysql_fetch_array($result_1))
{
echo "<tr>\n";
//echo "<td>" . $row['id'] . "</td>";
echo "<td><input type='hidden' name='".$myint."' size='10' maxlength='10' value=".$row['id']."></td>";
$myint = $myint +1;
echo '<td><select name= "'.$myint.'">';
for ($i=0; $i<=9; $i++)
{
if($row['priority'] == $i)
echo '<option value = '.$i.' selected = "'. $row['priority'] .'">'.$i.'</option>';
else
echo '<option value = '.$i.' >'.$i.'</option>';
}
echo '</select></td>';
$myint = $myint +1;
echo '<td><select name= "'.$myint.'">';
mysql_select_db("mytest", $con); // to:
$result_3 = mysql_query("SELECT mates FROM team");
if (!$result_3) {
echo 'Could not run query: ' . mysql_error();
exit;
}
while($team_1 = mysql_fetch_array($result_3))
{
if($row['whogets'] == $team_1["mates"]) // make sure there is 2 equals or otherwise you will set the value
echo '<option value="'. $team_1["mates"] .'" selected = "'. $team_1["mates"] .'">'. $team_1["mates"] .'</option>';
else
echo '<option value="'. $team_1["mates"] .'">'. $team_1["mates"] .'</option>';
}
echo '</select></td>' ;
$myint = $myint +1;
echo '<td><select name= "'.$myint.'">';
mysql_select_db("mytest", $con); // status:
$result_2 = mysql_query("SELECT status_ FROM rec_status");
if (!$result_2) {
echo 'Could not run query: ' . mysql_error();
exit;
}
while($rec_status = mysql_fetch_array($result_2))
{
if($row['status'] == $rec_status['status_']) // make sure there is 2 equals or otherwise you will set the value
echo '<option value="'. $rec_status['status_'] .'" selected = "'. $row['status'] .'">'. $rec_status['status_'] .'</option>';
else
echo '<option value="'. $rec_status['status_'] .'">'. $rec_status['status_'] .'</option>';
}
echo '</select></td>' ;
$myint = $myint +1;
echo "<td>" . $row['practname'] . "</td>";
echo "<td>" . $row['shortissue'] . "</td>";
//echo "<td>" . $row['holdfile'] . "</td>";
echo "</tr>";
}
?>
</table><br>
<INPUT TYPE= RESET VALUE = "Reset">
<INPUT TYPE= SUBMIT NAME="SUBMIT" VALUE = "Submit!">
</form>
This is how the $_post array looks when form is submitted
______________________________________...
Array ( [0] => 115 [1] => 0 [2] => Dan [3] => system code [4] => 135 [5] => 0 [6] => Dan [7] => waiting approval [8] => 165 [9] => 1 [10] => The Guys [11] => fixes [12] => 245 [13] => 0 [14] => Dan [15] => waiting approval [16] => 255 [17] => 1 [18] => The Guys [19] => fixes [20] => 375 [21] => 4 [22] => Dan [23] => waiting approval [24] => 405 [25] => 0 [26] => Dan [27] => waiting approval [28] => 415 [29] => 0 [30] => Dan [31] => waiting approval [32] => 495 [33] => 0 [34] => Dan [35] => waiting approval [36] => 525 [37] => 0 [38] => Dan [39] => waiting approval [40] => 555 [41] => 0 [42] => Dan [43] => waiting approval [44] => 565 [45] => 0 [46] => Dan [47] => fixes [48] => 575 [49] => 0 [50] => Tim [51] => fixes [52] => 615 [53] => 0 [54] => Tim [55] => internal approval [56] => 625 [57] => 0 [58] => Tim [59] => testing BFIS [60] => 645 [61] => 0 [62] => Dan [63] => fixes [64] => 655 [65] => 0 [66] => Dan [67] => fixes [68] => 665 [69] => 0 [70] => The Guys [71] => fixes [72] => 745 [73] => 0 [74] => The Guys [75] => new setup [76] => 755 [77] => 0 [78] => The Guys [79] => new setup [80] => 765 [81] => 0 [82] => The Guys [83] => new setup [84] => 775 [85] => 0 [86] => The Guys [87] => new setup [88] => 785 [89] => 0 [90] => Dan [91] => internal approval [92] => 795 [93] => 0 [94] => The Guys [95] => new setup [96] => 805 [97] => 0 [98] => Rachael [99] => fixes [100] => 835 [101] => 0 [102] => Dave [103] => fixes [104] => 855 [105] => 0 [106] => Tim [107] => waiting approval [108] => 865 [109] => 0 [110] => Dan [111] => waiting approval [112] => 895 [113] => 0 [114] => The Guys [115] => waiting approval [116] => 905 [117] => 0 [118] => The Guys [119] => waiting approval [120] => 925 [121] => 0 [122] => The Guys [123] => waiting approval [124] => 935 [125] => 0 [126] => The Guys [127] => waiting approval [128] => 945 [129] => 0 [130] => The Guys [131] => waiting approval [132] => 995 [133] => 0 [134] => The Guys [135] => waiting approval [136] => 1035 [137] => 0 [138] => The Guys [139] => waiting approval [140] => 1095 [141] => 0 [142] => Tim [143] => fixes [144] => 1105 [145] => 0 [146] => Tim [147] => waiting approval [148] => 1145 [149] => 0 [150] => Dan [151] => fixes [152] => 1185 [153] => 0 [154] => The Guys [155] => waiting approval [156] => 1215 [157] => 0 [158] => The Guys [159] => new setup [160] => 1225 [161] => 0 [162] => The Guys [163] => new setup [164] => 1235 [165] => 0 [166] => Dan [167] => fixes [168] => 1245 [169] => 0 [170] => The Guys [171] => new setup [172] => 1255 [173] => 0 [174] => Tim [175] => waiting approval [176] => 1275 [177] => 0 [178] => Tim [179] => fixes [180] => 1295 [181] => 0 [182] => Tim [183] => internal approval [184] => 1335 [185] => 0 [186] => Dan [187] => internal approval [188] => 1345 [189] => 3 [190] => Dan [191] => internal approval [192] => 1475 [193] => 0 [194] => Dan [195] => internal approval [196] => 1375 [197] => 0 [198] => The Guys [199] => new setup [200] => 1385 [201] => 0 [202] => Tim [203] => waiting approval [204] => 1405 [205] => 0 [206] => The Guys [207] => new setup [208] => 1425 [209] => 0 [210] => The Guys [211] => fixes [212] => 1445 [213] => 0 [214] => Dan [215] => waiting approval [216] => 1455 [217] => 0 [218] => Dan [219] => waiting approval [220] => 1515 [221] => 0 [222] => The Guys [223] => fixes [224] => 1525 [225] => 0 [226] => Tim [227] => internal approval [228] => 1535 [229] => 0 [230] => The Guys [231] => new setup [232] => 1545 [233] => 0 [234] => The Guys [235] => fixes [236] => 1555 [237] => 0 [238] => The Guys [239] => new setup [240] => 1565 [241] => 0 [242] => The Guys [243] => fixes [244] => 1575 [245] => 0 [246] => Dan [247] => fixes [248] => 1585 [249] => 0 [250] => The Guys [251] => new setup [252] => 1595 [253] => 0 [254] => Tim [255] => internal approval [256] => 1605 [257] => 0 [258] => Dan [259] => waiting approval [260] => 1625 [261] => 0 [262] => The Guys [263] => fixes [264] => 1635 [265] => 0 [266] => Dan [267] => waiting approval [268] => 1645 [269] => 0 [270] => Dan [271] => waiting approval [272] => 1655 [273] => 0 [274] => Dan [275] => fixes [276] => 1665 [277] => 0 [278] => The Guys [279] => fixes [280] => 1675 [281] => 0 [282] => Dan [283] => internal approval [284] => 1685 [285] => 0 [286] => Dan [287] => fixes [288] => 1695 [289] => 0 [290] => The Guys [291] => new setup [292] => 1705 [293] => 0 [294] => The Guys [295] => new setup [296] => 1715 [297] => 0 [298] => Dave [299] => fixes [300] => 1725 [301] => 0 [302] => Tim [303] => fixes [304] => 1735 [305] => 0 [306] => Dan [307] => internal approval [308] => 1745 [309] => 3 [310] => Dan [311] => internal approval [312] => 1755 [313] => 0 [314] => The Guys [315] => fixes [SUBMIT] => Submit! )
______________________________________...
I want to take the information from the $_post array and update a mysql db. Currently only the first record is updating. Below is my program to loop through the post array and post it into the database.
______________________________________...
<html>
<head><title>crank test updated</title></head>
<?php include("connection.php"); ?>
<?php
$myID = 0;
$myPriority = 1;
$myWhogets = 2;
$myStatus = 3;
$postSize = count($_POST)-1; //subract the submit element
$myTimer = $postSize/4; //size of array minus one element divided by the number of fields
$i = 0;
// $sql="update bunk3 set priority = " . "'" . $_POST['$myPriority'] . "'" . ', whogets = '$_POST['$myWhogets']', status = '$_POST['$myStatus']' where id = '$_POST['$myID']'";
mysql_select_db("mytest", $con);
do
{
// $sql= "update bunk3 set priority = '" . $_POST[$myPriority] . "' where id = '" . $_POST[$myID] . "'"; shows on first loop
$sql= "update bunk3 set priority = '" . $_POST[$myPriority] . "' where id = '" . $_POST[$myID] . "'";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo 'top<br>';
echo $sql.'<br>';
echo $myID = $myID + 4 .'<br>';
echo $myPriority = $myPriority + 4 .'<br>';
echo $myWhogets = $myWhogets + 4 .'<br>';
echo $myStatus = $myStatus + 4 .'<br>';
echo $i = $i + 1 .'<br>';
echo $_POST[$myPriority].' for Dave <br>';
echo $postSize . ' size of array<br>';
}
while ($i != $myTimer);
?>
<?php include("test_crank.php"); ?>
--------------------------------------...
I have echoed the variables out to see that they are incrementing ok. I also echoed the sql statement to see if the array elements are there and that's how I know that only the first time through the loop is showing up.
Tags: