我有一个带有复选框的HTML表格,它会显示来自MYSQL数据库的行。 问题是当我标记其中一行要对其执行某些操作时,它会给我一个错误的值,但是MYSQL代码正在正确运行并且更新了右行, 我很困惑,无法确定问题是什么,它一直工作到一个小时前。 我已经使用echo函数来查看值的结果,每次它为$ i显示零并且数组为零地址,但是MYSQL UPDATE代码得到正确的值并更新正确的行。
HTML表格:
<?php
$connection = mysql_connect('localhost', '', '');
$db = mysql_select_db('table', $connection);
mysql_query("SET CHARACTER SET utf8;");
mysql_query("SET SESSION collation_connection = 'utf8_persian_ci'");
/* Inbox section */
$query = mysql_query("SELECT * FROM article WHERE editor='' && status='Under Review' ", $connection);
$string = '';
if (mysql_num_rows($query)){
$_SESSION["count"]=mysql_num_rows($query);
?>
<form method="POST" action="">
<table cellspacing='0' width="800" border='1'>
<tr>
<th>Title</th>
<th>Firstname</th>
<th>Lirstname</th>
<th>Article Title</th>
<th>Article File</th>
<th>Reviewer Email Address</th>
<th>Mark</th>
</tr>
<?php while($row = mysql_fetch_assoc($query)){ ?>
<tr>
<td align='center'><input type='text' name='title[]' id='title' value= "<? echo $row['title']; ?>" ></td>
<td align='center'><input type='text' name='fname[]' id='fname' value= "<? echo $row['fname']; ?>" ></td>
<td align='center'><input type='text' name='lname[]' id='lname' value= "<? echo $row['lname']; ?>" ></td>
<td align='center'><input type='text' name='mastitle[]' id='mastitle' value= "<? echo $row['mstitle']; ?>"></td>
<td align='center'><input type='text' name='file[]' id='file' value="<? echo $row['msfile']; ?> "></td>
<td align='center'><input type='text' name='editoremail[]' id='editoremail' ></td>
<td align="center"><inputtype="checkbox" name="checkbox[]" id="checkbox" value="<? echo $row['id']; ?>" /></td>
</tr>
<?php } ?>
</table>
<div class='cleaner h10'></div>
<input type='submit' name='send' id='send' value='Send'>
</form>
php代码:
<?php
// Check if button name "Submit" is active, do this
if(isset($_POST['send']) && $_POST['send'] == 'Send')
{
for($i=0;$i<=$_SESSION["count"];$i++)
{
if(isset($_REQUEST['checkbox'][$i]))
{
$set_id = $_REQUEST['checkbox'][$i];
$sql_new=mysql_query(" UPDATE `article` SET `editor`='SENT' WHERE `id`='$set_id' ", $connection);
echo $i;
echo "<br>" . $article=$_REQUEST['file'][$i];
echo "<br>" . $TOmail=$_REQUEST['editoremail'][$i];
echo "<br>" . $manutitle=$_REQUEST['mastitle'][$i];
}
}
}
?>
答案 0 :(得分:0)
<?php
$row_counter = 0;
while($row = mysql_fetch_assoc($query)){ ?>
<tr>
<td align='center'><input type='text' name='title[]' id='title' value= "<? echo $row['title']; ?>" ></td>
<td align='center'><input type='text' name='fname[]' id='fname' value= "<? echo $row['fname']; ?>" ></td>
<td align='center'><input type='text' name='lname[]' id='lname' value= "<? echo $row['lname']; ?>" ></td>
<td align='center'><input type='text' name='mastitle[]' id='mastitle' value= "<? echo $row['mstitle']; ?>"></td>
<td align='center'><input type='text' name='file[]' id='file' value="<? echo $row['msfile']; ?> "></td>
<td align='center'><input type='text' name='editoremail[]' id='editoremail' ></td>
<td align="center"><inputtype="checkbox" name="checkbox[]" id="checkbox" value="<? echo $row['id'].'_'.$row_counter++; ?>" /></td>
</tr>
<?php } ?>
$a_set_id = explode('_', $_REQUEST['checkbox'][$i]);
$set_id = $a_set_id[0];
$row_no = $a_set_id[1];
$sql_new=mysql_query(" UPDATE `article` SET `editor`='SENT' WHERE `id`='$set_id' ", $connection);
echo $i;
echo "<br>" . $article=$_REQUEST['file'][$row_no];
echo "<br>" . $TOmail=$_REQUEST['editoremail'][$row_no];
echo "<br>" . $manutitle=$_REQUEST['mastitle'][$row_no];