PHP从多个HTML更新SQL复选框
因此,我需要确保在按下按钮时为DB设置正确的参数。我只想让通话和比较正确,这样当我按下按钮时,它就会做它应该做的事情。对于数据库中的每一行,应该有一个删除按钮,当我按下它时更新页面 通过更改表单并按下保存按钮,然后刷新页面,应该可以更新MySQL呈现的表单中的文本/数字PHP从多个HTML更新SQL复选框,php,html,checkbox,Php,Html,Checkbox,因此,我需要确保在按下按钮时为DB设置正确的参数。我只想让通话和比较正确,这样当我按下按钮时,它就会做它应该做的事情。对于数据库中的每一行,应该有一个删除按钮,当我按下它时更新页面 通过更改表单并按下保存按钮,然后刷新页面,应该可以更新MySQL呈现的表单中的文本/数字 $counter = 1; if(isset($_POST['save']) and something is changed from the forms compared to DB) { Update MySQL Re
$counter = 1;
if(isset($_POST['save']) and something is changed from the forms compared to DB) {
Update MySQL
Refresh page
<script>
window.location.replace("thispage.php");
</script>
}
if(isset($_POST['del'])) {
DELETE MySQL
Refresh page
<script>
window.location.replace("thispage.php");
</script>
}
echo "<tr><td>ID</td><td>Namn</td><td>Platser</td><td>Fullbokad</td><td>Ta bort</td></tr>";
$sqlListSections = "SELECT * FROM avdelningar WHERE user = {$_SESSION['id']}";
$queryListSections = mysqli_query($mysqli, $sqlListSections);
$del = [];
while($rowListSections = mysqli_fetch_array($queryListSections))
{
if($counter%2)
{
echo "\n<tr bgcolor=#F1F1F2>\n\n";
}else
{
echo "\n<tr bgcolor=#FFFFFF>\n\n";
}
$counter++;
echo "
<td>".$rowListSections['id']."</td>
<td>
<input type=text value=".$rowListSections['namn']."></td>
<td>
<input type=text value=".$rowListSections['platser']."></td>
<td>";
if($rowListSections['prio'] == 1)
{
echo "<select name=platser>
<option selected value=".$rowListSections['prio'].">".$rowListSections['prio']."</option>
<option value='0'>0</option>".$rowListSections['prio'];
}elseif($rowListSections['prio'] == 0)
{
echo "<select name=platser>
<option selected value=".$rowListSections['prio'].">".$rowListSections['prio']."</option>
<option value='1'>1</option>".$rowListSections['prio'];
}
echo "</td>
<td>
<form method=post action=thispage.php>
<input type=submit value=Delete name=del>";
</td>
</form>
</tr>";
}
echo "<form method=post action=thispage.php>
<input type=submit value=Save name=save>";
`
$counter=1;
如果(设置($_POST['save']),与DB相比,表单中的某些内容发生了更改){
更新MySQL
刷新页面
window.location.replace(“thispage.php”);
}
如果(isset($_POST['del'])){
删除MySQL
刷新页面
window.location.replace(“thispage.php”);
}
回声“IDNamnPlatserFullbokadTa bort”;
$sqlListSections=“从avdelningar中选择*,其中用户={$\u会话['id']}”;
$queryListSections=mysqli\u查询($mysqli,$sqlListSections);
$del=[];
而($rowListSections=mysqli\u fetch\u数组($queryListSections))
{
如果($counter%2)
{
回显“\n\n\n”;
}否则
{
回显“\n\n\n”;
}
$counter++;
回声“
“$rowListSections['id']”
";
if($rowListSections['prio']==1)
{
回声“
“$rowListSections['prio']”
0.“$rowListSections['prio'];
}elseif($rowListSections['prio']==0)
{
回声“
“$rowListSections['prio']”
1.“$rowListSections['prio'”;
}
回声“
";
";
}
回声“
";
`
在复选框中更改命名为数组
像
$rowListSections[“prio”]。'
在你的if(isset($\u POST))
中,你可以得到一个del
数组,这样你就可以像下面那样循环这个数组
foreach($del as $val){
$id = $val;
$sql_query_for_update = "update table_name set field = 1 where id= '$id' ";
}
你能给出详细的想法吗?你想实现什么?我想标记我想删除的部分,按保存按钮,删除所有选中的部分,并显示我不理解的新结果。我不能写name=del[]我的复选框行中没有错误。你能给我所有的代码示例吗?我仍然不明白。我无法在中写入del[]吗?这是一个数组,没有$?是的!如果你在名称中输入[],它将被视为数组。例如:如果你提交此表单,那么你将得到所有选中的复选框作为数组。
($\u POST['del']=[0=>'val',1=>'val1']
)如果您不明白,请告诉我:)看起来很棒!我今晚回家后会试试!我希望del[]现在可以用了!谢谢!
foreach($del as $val){
$id = $val;
$sql_query_for_update = "update table_name set field = 1 where id= '$id' ";
}