gpt4 book ai didi

php - 如何将一个值插入到不同的行

转载 作者:行者123 更新时间:2023-11-29 13:56:28 25 4
gpt4 key购买 nike

我希望代码将相同的值插入到列表中检查的不同行(该列表是从数据库查询的。)但它说
“注意:第 5 行\enrol.php 中的数组到字符串转换”,

这是我的section.php

    <table border=1px>
<th>SELECT</th>
<th>ID NUMBER</th>
<th>NAME</th>
<th>COURSE</th>
<th>YEAR</th>

<?php session_start();
include('connect.php');
$group=$_REQUEST['idEdit'];
echo $group;

$sql="SELECT * FROM login WHERE section IS NULL or section = 0";
$result=mysql_query($sql) or die(mysql_error() );


while($arr=mysql_fetch_array($result))
{
echo '<tr><td><form action="enrol.php" method="post"><input type="checkbox" name="idnumber[]" value="'.$arr['idnumber'].'"></td>'.
'<td>'.$arr['idnumber'].",&nbsp</td>".
'<td>'.$arr['lastname'].",".$arr['firstname']."&nbsp</td>".
'<td>'.$arr['course']."&nbsp</td>".
'<td>'.$arr['year']."&nbsp</td></tr>";}

$idnumber=$arr['idnumber'];
?>

<input type="hidden" value="<?php $group ?>" name="group">
<input type="submit" value="Enrol Student" name="submit">
</form>
</table>

这是我的 enrol.php

    <?php 
if(isset($_REQUEST['submit'])){

$ids = join (', ', $_POST['idnumber']);
$sql="INSERT INTO login (section) values ('$_POST[group]') WHERE idnumber='$ids'";
mysql_query($sql);

$count=mysql_affected_rows();

if($count==1){
echo '<script type="text/javascript">alert("Added Sucessfully")</script>';

}else{
echo '<script type="text/javascript">alert("Error!")</script>';

}
}
?>

我该如何解决这个问题?我一直在尝试寻找解决方案,但似乎找不到任何解决方案。请帮忙。

最佳答案

我认为,您得到的隐藏字段组值为空。首先,您在隐藏字段中回显组值。

<input type="hidden" value="<?php echo $group; ?>" name="group">

希望您的问题能够得到解决。你明白我的意思了吗?

关于php - 如何将一个值插入到不同的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15785264/

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