gpt4 book ai didi

php - 从不使用存储过程的数据库中编辑和删除特定行

转载 作者:行者123 更新时间:2023-11-29 19:15:37 26 4
gpt4 key购买 nike

我使用以下代码删除特定行,但无法正常工作。我有两个文件,一个是brand.php,一个是delete.php。这是代码。如何从数据库中删除特定行。 enter image description here enter image description here

品牌.php

$sql = "http://www.query.mydomain.com/default.aspx?dbname=compname_dbName&query=select Code, Id, Name from Brand where CompanyCode = 87";
$sqlquery = str_replace ( " ", "%20", $sql );
$json = file_get_contents ( $sqlquery );
$data = json_decode ( $json, TRUE );
$result = array ();
$i = 1;
foreach ( $data as $item ) {
$Rowid = $item ['Code'];
$BId = $item ['Id'];
$BName = $item ['Name'];
?>
<form method = "post" action = "">
<tbody>
<tr>
<td> <?php echo $Rowid; ?> </td>
<td><?php echo $BId; ?> </td>
<td><?php echo $BName; ?> </td>
<td><p data-placement="top" data-toggle="tooltip" title="Edit">
<button class="btn btn-primary btn-xs" data-title="Edit" data-toggle="modal" data-target="#edit">
<span class="glyphicon glyphicon-pencil"></span>
</button>
</p></td>
<td><p data-placement="top" data-toggle="tooltip" title="Delete">
<a href="delete.php?rid=<?php echo $Rowid; ?>"><button type="submit" id="rid" name="rid" class="btn btn-danger btn-xs">
<span class="glyphicon glyphicon-trash"></span></button></a>
</p></td>
</tr>
</tbody>
</form>
<?php $i++; } ?>
</table>

删除.php

$Rowid=$_GET['rid'];
$sql = "http://www.query.mydomain.com/default.aspx?dbname=" . $GLOBALS ['strDB'] . "&query=Delete From sp_DelBrand Where Code = ".$Rowid."";
$sqlquery = str_replace ( " ", "%20", $sql );
$json = file_get_contents ( $sqlquery );
$data = json_decode ( $json, TRUE );
$resultID;
$Result1 = ' ';
foreach ( $data as $item ) {
$Result1 = $item ['Result'];
$resultID = $item ['ResultId'];
}
foreach($data as $item)
{
$Result1 = $item['Result'];
$resultID = $item['ResultId'];
}
echo '<script type="text/javascript">';
echo 'alert("'.$Result1.'");';
echo '</script>';
if (!isset($Result1))
{
echo '<script type="text/javascript">window.history.go(-1);</script>';
}
else
{
echo '<script type="text/javascript">window.history.go(-1);</script>';
}
}
?>

点击删除图标后,没有任何重定向到delete.php?id=rowid的迹象,但是页面加载并返回brand.php,并且行记录没有被删除,我这是怎么了!!

最佳答案

这是 PDO 连接和删除行查询:

<?php

$id = 5;

$dbh = new PDO('mysql:host=localhost;dbname=deletelimit10', "root", "");

$query = $dbh->query("DELETE FROM content WHERE id = '$id'"); // Run your query

?>

关于php - 从不使用存储过程的数据库中编辑和删除特定行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42739851/

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