[英]PHP update SQL from multiple HTML checkbox
So, I need to make sure this sets the right parameters to the DB when pressing the buttons. 因此,我需要确保在按下按钮时为数据库设置正确的参数。 I just want to get the calls and comparisons right so it does what it should when I hit the buttons.
我只是想正确地进行调用和比较,因此它可以按我的按钮进行操作。 There should be one delete button for each row from database, and update page when I press it.
数据库中的每一行应该有一个删除按钮,当我按下它时更新页面。
It should be possible to update the text/numbers in the forms presented by MySQL by changing the forms and press Save-button, then refresh the page. 通过更改表格并按保存按钮,然后刷新页面,应该可以更新MySQL所提供表格中的文本/数字。
$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>";
`
in your checkbox change naming as array. 在您的复选框中更改命名为数组。
<input type=checkbox name="del[]" value={$rowListSections['id']}>
like 喜欢
echo $rowListSections["id"].' '.$rowListSections["namn"].' '.$rowListSections["platser"].' '.
$rowListSections["prio"].''; $ rowListSections [“ prio”]。'';
and in your if(isset($_POST))
you can get a del
array so you can loop this array like below. 并且在您的
if(isset($_POST))
您可以获取一个del
数组,以便可以像下面这样循环该数组。
foreach($del as $val){
$id = $val;
$sql_query_for_update = "update table_name set field = 1 where id= '$id' ";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.