【发布时间】:2017-11-12 16:55:01
【问题描述】:
我知道 Mysqli 已解密,但服务器不允许我在 Mysqli 下划线,但目前这不是我的问题,我的问题是,如果我的复选框未选中,它不会更新到 0 其中从 if then 声明 else。
<?php
@mysql_connect("localhost", "xxx", "xxx") or die(mysql_error());
@mysql_select_db("xxx") or die(mysql_error());
@mysql_query("SET NAMES utf8"); error_reporting(E_ALL);
ini_set('display_errors', 1);
$chk1 = $_POST['chk1'];
foreach($chk1 as $i=>$s){
if($s == TRUE)
{
echo $s, '<br/>';
$sql = mysql_query("UPDATE `xxx`.`cars` SET `show` = '1' WHERE cars_id='".$s."'");
} else {
echo $s, '<br/>';
$sql = mysql_query("UPDATE `xxx`.`cars` SET `show` = '0' WHERE cars_id='".$s."'");
}
}
?>
*添加
<form action="./pages/checkbox.php" method="post">
<section class="content" class="table details">
<table class="dashboard">
<tr class="top">
<td width="40">#</td>
<td width="40"Show</td>
<td width="40">Photo</td>
<td width="80%"Name</td>
</tr>
<tbody id="the-list">
<?
$result= mysql_query("SELECT * FROM cars");
$counter = 1;
?>
<?php
while($row = mysql_fetch_array($result)){
echo '<tr>
<td>' . $counter++ . '</td>
<td><input value="'.$row['cars_id'].'" id="chk1" name="chk1[]" type="checkbox"';
if ($row['show'] == true){
echo 'checked></td>';
}else
{
echo 'unchecked></td>';
}
echo '<td><img src="../xml/images/'.$row['cars_id'].'-1.JPG" width="120px"></td>';
echo "<td><h3> ", $row['brand']," " . $row['model'], " " . $row['type'], " € " . $row[cars_id'], " </h3></td>";
echo '</tr>';
}
?> <input type="submit" name="Submit" value="Safe">
</form>
在“重复”帖子中,我没有找到如何将其放入 while 循环中,请描述这是同一个问题。
【问题讨论】:
-
不,因为我在那篇文章中没有看到在我的表单中隐藏了一段时间。 - 循环
-
如果您在不那么重复的帖子中找不到清晰的遮阳篷,这会让人们有点害怕提问,因为我真的没有看到我正在寻找的问题。