很抱歉,如果之前已经解决了这个问题,但我已经在这里和其他地方寻找过解决方案,似乎无法找出原因并不起作用。
所以我有一个从数据库中提取数据的表单。这些字段是输入文本框,旁边有复选框,以便用户可以更新标题,URL并选择每个字段是活动还是非活动。
问题有点难以解释,但似乎只更新了一行。我在这里错过了什么或做错了什么?
感谢您的帮助! Siafu
所以,rssfeeds.php:
echo "<form name='rssfeedupdate' action='rssfeeds_update.php' method='POST'>
<table width='100%' border='0'>";
// SELECT DATA FROM DB
$result_rss = @mysql_query("SELECT * FROM rss_feeds ORDER BY status DESC, title") or die(mysql_error());
$count = mysql_num_rows($result_rss);
while ($row = mysql_fetch_array($result_rss)) {
$id = $row['id'];
$title = $row['title'];
$feedurl = $row['feed'];
$status = $row['status'];
echo "<tr>
<td valign='top'>
$id <input type='text' name='title[]' value='$title' size='20%'></input>
</td>
<td valign='top'>
<input type='text' name='feedurl[]' value='$feedurl' size='60%'></input>
</td>
<td valign='top' align='center'>";
if($status == 'on') {
$checked = "checked";
} else {
$checked = "";
}
echo "
<input type='checkbox' name='status[]' $checked></input>";
echo "</td>
</tr>
<tr>
<td valign='top' align='center' colspan='4'>
<br><hr><br>
</td>
</tr>";
<input type='hidden' name='id[]' value='$id'></input>
}
echo "</table>
<input type='hidden' name='count' value='$count'></input>
<table width='100%' border='0'>
<tr>
<td valign='top' align='right' colspan='4'>
<input type='submit' name='submit' value='Update Feeds'></input>
</td>
</tr>
</table>
</form>";
rssfeeds_update.php:
// LETS GET INFO FROM rssfeeds.php
if(isset($_POST['id'])) {
$id = $_POST['id'];
}
if(isset($_POST['count'])) {
$count = $_POST['count'];
}
if(isset($_POST['title'])) {
$title = $_POST['title'];
}
if(isset($_POST['feedurl'])) {
$feedurl = $_POST['feedurl'];
}
if(isset($_POST['status'])) {
$status = $_POST['status'];
}
for($i=0; $i<$count; $i++) {
echo "<table width='100%' border='0'>
<tr>
<td valign='top' width='5%'>
$id[$i]
</td>
<td valign='top' width='20%'>
$title[$i]
</td>
<td valign='top' width='60%'>
$feedurl[$i]
</td>
<td valign='top' width='10%'>
$status[$i]
</td>
</tr>
</table>";
$Update_Feeds = "UPDATE rss_feeds SET title='$title[$i]', feed='$feedurl[$i]', status='$status[$i]' WHERE id='$id[$i]'";
}
if (!mysql_query($Update_Feeds, $link)) {
die('<br><br>Error: ' . mysql_error());
} else {
echo "<br><br>RSS feeds updated successfully! <a href='rssfeeds.php'>Go Back</a>";
}