gpt4 book ai didi

php - 从复选框中获取错误的变量

转载 作者:行者123 更新时间:2023-11-30 00:34:32 27 4
gpt4 key购买 nike

我有一个 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];

}
}
}
?>

最佳答案

<?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];

关于php - 从复选框中获取错误的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22283833/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com