gpt4 book ai didi

php - 不会按 id 过滤更新查询

转载 作者:行者123 更新时间:2023-11-29 22:09:15 25 4
gpt4 key购买 nike

我有一个网站后端部分的代码,可以提取“快速链接”并允许在面板中对其进行编辑。当我不将“WHERE”子句添加到 SQL 时,它会更新所有快速链接,但是当我按 ID 过滤时,它不起作用。

<?php

$query = "SELECT id,title,picture,link,alt,button,active FROM quicklinks" or die("Error!:" . mysqli_error($link));
$result = $link->query($query);
$title = $_REQUEST["title"];
$picture = $_REQUEST["picture"];
$id = $_REQUEST["id"];
?>
<?php


while($row = mysqli_fetch_array($result))
{
if (isset($_REQUEST['update']))
{
mysqli_query($link,"UPDATE quicklinks SET title='$title', picture='$picture' WHERE ID='$id' ");
}
echo "<form method='post'><div id='ql" . $row["id"] . "' class='modal fade' role='dialog'> <div class='modal-dialog'><div class='modal-content'><div class='modal-header'><button type='button' class='close' data-dismiss='modal'>&times;</button><h4 class='modal-title'>Editing " . $row["title"] . "</h4></div><div class='modal-body'>
<div class='input-group'>
<span class='input-group-addon' id='basic-addon1'>Quick Link ID is: </span>
<input type='text' name='id' class='form-control' value='" . $row["id"] . "' disabled='disabled'></div></br>
<div class='input-group'>
<span class='input-group-addon' id='basic-addon1'>Title: </span>
<input name='title' type='text' id='inputHelpBlock' class='form-control' value='" . $row["title"] . "'> </div></br>
<div class='input-group'>
<span class='input-group-addon' id='basic-addon1'>Link: </span>
<input name='link' type='text' id='inputHelpBlock' class='form-control' value='" . $row["link"] . "'> </div></br>
<div class='input-group'>
<span class='input-group-addon' id='basic-addon1'>Image URL: </span>
<input name='picture' type='text' id='inputHelpBlock' class='form-control' value='" . $row["picture"] . "'> </div></br>
<div class='input-group'>
<span class='input-group-addon' id='basic-addon1'>Image Alt Text: </span>
<input name='alt' type='text' id='inputHelpBlock' class='form-control' value='" . $row["alt"] . "'> </div></br>
<div class='input-group'>
<span class='input-group-addon' id='basic-addon1'>Button Text: </span>
<input name='button' type='text' id='inputHelpBlock' class='form-control' value='" . $row["button"] . "'> </div></br></div>
<div class='modal-footer'><button type='button' class='btn btn-default' data-dismiss='modal'>Close</button><input name='update' type='submit' class='btn btn-success' value='Apply'></div></div></div></div></form>";
} ?>

最佳答案

如果 id 在数据库中是小写字母,那么您应该按照查询中的方式编写它。另外,如果它是整数,请删除引号。

mysqli_query($link,"UPDATE quicklinks SET title='$title', picture='$picture' WHERE id=$id ");

编辑

我发现你的代码实际上是一团糟。这是修改后的代码

<?php

$query = "SELECT id,title,picture,link,alt,button,active FROM quicklinks" or die("Error!:" . mysqli_error($link));
$result = $link->query($query);
$title = $_REQUEST["title"];
$picture = $_REQUEST["picture"];
$id = $_REQUEST["id"];

if ($_GET['do'] == "update") {
mysqli_query($link,"UPDATE quicklinks SET title='$title', picture='$picture' WHERE id=$id ");
}
?>
<?php


while($row = mysqli_fetch_array($result))
{

echo "<form method='post' action='?do=update' ><div id='ql" . $row["id"] . "' class='modal fade' role='dialog'> <div class='modal-dialog'><div class='modal-content'><div class='modal-header'><button type='button' class='close' data-dismiss='modal'>&times;</button><h4 class='modal-title'>Editing " . $row["title"] . "</h4></div><div class='modal-body'>
<div class='input-group'>
<span class='input-group-addon' id='basic-addon1'>Quick Link ID is: </span>
<input type='text' name='id' class='form-control' value='" . $row["id"] . "' disabled='disabled'></div></br>
<div class='input-group'>
<span class='input-group-addon' id='basic-addon1'>Title: </span>
<input name='title' type='text' id='inputHelpBlock' class='form-control' value='" . $row["title"] . "'> </div></br>
<div class='input-group'>
<span class='input-group-addon' id='basic-addon1'>Link: </span>
<input name='link' type='text' id='inputHelpBlock' class='form-control' value='" . $row["link"] . "'> </div></br>
<div class='input-group'>
<span class='input-group-addon' id='basic-addon1'>Image URL: </span>
<input name='picture' type='text' id='inputHelpBlock' class='form-control' value='" . $row["picture"] . "'> </div></br>
<div class='input-group'>
<span class='input-group-addon' id='basic-addon1'>Image Alt Text: </span>
<input name='alt' type='text' id='inputHelpBlock' class='form-control' value='" . $row["alt"] . "'> </div></br>
<div class='input-group'>
<span class='input-group-addon' id='basic-addon1'>Button Text: </span>
<input name='button' type='text' id='inputHelpBlock' class='form-control' value='" . $row["button"] . "'> </div></br></div>
<div class='modal-footer'><button type='button' class='btn btn-default' data-dismiss='modal'>Close</button><input name='update' type='submit' class='btn btn-success' value='Apply'></div></div></div></div></form>";
}
?>

关于php - 不会按 id 过滤更新查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31851625/

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