Page is a not externally linkable
- Code, Content, and Presentation
-- PHP Server Side Scripting
---- update form array not working


nickelman - 1:39 pm on Sep 25, 2010 (gmt 0)


This is an overly simplified version:



<?php
mysql_select_db($database_reports, $reports);
$query_game = "SELECT * FROM game_list WHERE type_reports > -1 ORDER BY name_reports";
$game_sel = mysql_query($query_game, $reports) or die(mysql_error());
$game[] = mysql_fetch_assoc($game_sel);
$count = 0; ?>

<form action="earnings_update.php" method="post" name="get_game" id="get_game" >
<table border="1">
<tr>
<td colspan=3>Game Earnings Update<input name="pull_date" type="hidden" value="<?php echo date("Y-m-d"); ?>" id="pull_date"></td>
</tr>
<tr>
<td>Count</td>
<td>Game Name</td>
<td>Enter Value</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $count + 1; ?></td>
<td><?php echo $game[$count]['name_reports']; ?></td>
<td>
<input name="game_count[]" type="text" size="10" maxlength="10" >
<input name="game_id[]" type="hidden" id="game_id" value="<?php echo $game[$count]['ids'] ?>" ></td>
</tr>

<?php $count = $count + 1; ?>
<?php } while ($game[] = mysql_fetch_assoc($game_sel)); ?>
</table>
<input name="Submit" type="submit" id="Submit" value="Submit" >
</form>


And the insertion code:


<?php
mysql_select_db($database_reports, $reports);
$game_id[] = ($_POST['game_id']);
$game_count[] = ($_POST['game_count']);
$detail_count = count($_POST['game_id']);
$pull_date = ($_POST['pull_date']);

echo "Please Wait While Records Are Being Updated<br>";

if ( is_array($_POST['game_count'] ) ) {
for ($i = 0; $i < $detail_count; $i++) {
if (isset($game_count[$i]) && $game_count[$i] <> "") {

$result = mysql_query ("INSERT INTO game_earnings VALUES (
'{0}',
'{$game_id[$i]}',
'{$game_count[$i]}',
'{$pull_date}')");
}
}
}
echo "<br>";
echo "Update complete."; ?>



Thread source:: http://www.webmasterworld.com/php/4199464.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com