我的代码又出现了另一个问题。
我从SQL内容生成动态表,并使用表中的文本字段,可能有一天,更改内容。
问题是,我无法访问while循环外部的文本域来保存内容,我得到的是每个字段的未定义索引错误。
<form method="POST" enctype="text/html">
<?php
require_once ('config.php');
$sql = " SELECT * FROM kassen ORDER BY name ASC ";
$db_erg = mysql_query( $sql );
echo "<tr>";
echo "<td>";
echo '<table border="1" width="80%" align="center">';
echo "<tr> <th>Name</th><th>Stand</th><th>Verbrauch</th><th>Einzahlungen</th></tr>";
while ($zeile = mysql_fetch_assoc($db_erg))
{
echo '<tr>';
echo '<td>'. $zeile['name'] . '</td>';
echo '<td><center>'. $zeile['bier_stand'] . '€</td>';
echo '<td>';
/* in the text below, i set the name to verbrauch"'.$zeile['id'] and
ergebnis"'.$zeile['id'] which should generate a new unique name for every
single text*/
echo '<center><input type="text" name="verbrauch"'.$zeile['id'].' value="0" size="10" />';
echo '</td>';
echo '<td>';
echo '<center><input type="text" name="einzahlung"'.$zeile['id'].' value="0" size="10" />';
echo '</td>';
echo '</tr>';
} echo '</table>';
?>
<center><input type="hidden" name="aktion" value="speichern" />
<center><input type="Submit" name="" value="speichern"/>
</form>
<?php
if (isset ($_POST['aktion']))
{
if ($_POST['aktion'] == "speichern" )
{
require_once ('config.php');
$sql = " SELECT * FROM kassen ORDER BY name ASC ";
$db_erg = mysql_query( $sql );
while ($zeile = mysql_fetch_assoc($db_erg))
{
$standalt = $zeile["bier_stand"];
/* now I try to put the value of the text to the DB, but all i get is
Undefined Index error */
$verbrauch = $_POST['verbrauch'.$zeile['id']];
$einzahlung = $_POST['einzahlung'.$zeile['id']];
$stand = $zeile["bier_stand"] - $verbrauch + $einzahlung;
$id = $zeile["id"];
$sql = "UPDATE kassen SET ";
$sql .= " bier_stand_alt = '$standalt', ";
$sql .= " bier_stand = '$stand', ";
$sql .= " bier_verbrauch = '$verbrauch', ";
$sql .= " bier_einzahlungen = '$einzahlung' ";
$sql .= " WHERE id='$id'";
}
echo '<h2>Änderungen übernommen</h2>';
echo '<a href="bierkasse.php">zurück zur Bierkasse</a>';
exit;
}
}
?>
知道我搞砸了什么吗?
答案 0 :(得分:0)
对不起提问,
真是个愚蠢的错误
echo '<center><input type="text" name="einzahlung"'.$zeile['id'].' value="0" size="10" />';
应该是
echo '<center><input type="text" name="einzahlung'.$zeile['id'].'" value="0" size="10" />';
所以实际上只是“在错误的地方......愚蠢的事情发生在凌晨3点