我有一个PHP代码的工作设置,突然之间没有任何工作,我不太确定我是否在某处意外地在代码中做错了。
基本上我有一个从数据库中读取一些数据的php并将其填充到表中,以便我可以对其进行分组编辑。但是当点击提交按钮时,就不再发生任何事情了。
也许有人会立即发现错误。
这是用于提取数据并创建表格的PHP:
<form method="post" action="fxgroupedit.php">
<table border="1">
<tr>
<td>n</td>
<td>ID</td>
<td>Year</td>
<td>Month</td>
<td>Day</td>
<td>Issue</td>
<td>Revenue</td>
<td>Category</td>
<td>Sub Category</td>
</tr>
<?php include("db_fx.php");
$sql = "SELECT * FROM tbl_data WHERE category=''";
$result = mysql_query($sql);
$n=0;
while ($line = mysql_fetch_array($result))
{
$n++;
?>
<tr>
<td><?PHP echo $n?></td>
<td><input style="width: 30px" name="id<?echo $n?>" value="<?PHP echo $line[id];?>"</td>
<td><input style="width: 40px" name="year<?echo $n?>" value="<?PHP echo $line[year];?>"</td>
<td><input style="width: 30px" name="month<?echo $n?>" value="<?PHP echo $line[month];?>"</td>
<td><input style="width: 30px" name="day<?echo $n?>" value="<?PHP echo $line[day];?>"</td>
<td><input style="width: 400px" name="issue<?echo $n?>" value="<?PHP echo $line[issue];?>"</td>
<td><input style="width: 50px" name="rev<?echo $n?>" value="<?PHP echo $line[rev];?>"</td>
<td><select name="category<?echo $n?>"
<?php
$sql = "SELECT DISTINCT category FROM tbl_data ORDER BY category";
$rs = mysql_query($sql);
echo '<option value=""></option>';
while($row = mysql_fetch_array($rs))
{
echo "<option value=\"".$row['category']."\">".$row['category']."</option>\n ";
}
?>
</select></td>
<td><select name="sub_category<?echo $n?>"
<?php
$sql = "SELECT DISTINCT sub_category FROM tbl_data ORDER BY sub_category";
$rs = mysql_query($sql);
echo '<option value=""></option>';
while($row = mysql_fetch_array($rs))
{
echo "<option value=\"".$row['sub_category']."\">".$row['sub_category']."</option>\n ";
}
?>
</select></td>
</tr>
<?PHP
}
//mysql_free_result($result);
mysql_close();
?>
</table>
<input type="hidden" name="rows" value="<?echo $n?>" />
<input type="submit" />
</form>
这里是fxgroupedit.php脚本,通常可以解决这个问题:
<table border="1">
<tr>
<td>n</td>
<td>ID</td>
<td>Year</td>
<td>Month</td>
<td>Day</td>
<td>Issue</td>
<td>Revenue</td>
<td>Category</td>
<td>Sub Category</td>
</tr>
<?PHP include("db_fx.php");
$fx_rows=$_POST['rows'.$n];
$n=0;
while($n < $fx_rows)
{
$n++;
$fx_id=$_POST['id'.$n];
$fx_year=$_POST['year'.$n];
$fx_month=$_POST['month'.$n];
$fx_day=$_POST['day'.$n];
$fx_issue=$_POST['issue'.$n];
$fx_rev=$_POST['rev'.$n];
$fx_category=$_POST['category'.$n];
$fx_sub_category=$_POST['sub_category'.$n];
$sql="UPDATE tbl_data SET
year='$fx_year',
month='$fx_month',
day='$fx_day',
issue='$fx_issue',
rev='$fx_rev',
category='$fx_category',
sub_category='$fx_sub_category'
WHERE
id='$fx_id'";
mysql_query($sql);
print mysql_error();
echo $fx_rows;
?>
<tr>
<td><?php echo $n ?></td>
<td><?php echo $fx_id ?></td>
<td><?php echo $fx_year ?></td>
<td><?php echo $fx_month ?></td>
<td><?php echo $fx_day ?></td>
<td><?php echo $fx_issue ?></td>
<td><?php echo $fx_rev ?></td>
<td><?php echo $fx_category ?></td>
<td><?php echo $fx_sub_category ?></td>
</tr>
<?PHP
}
?>
</table>
谢谢!