gpt4 book ai didi

mysql - 选择不起作用后删除

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

在这个网站中,我正在开发一个正品产品代码验证系统,因此当用户在表单中插入代码时,这将显示他们的产品是否是正品,但用户只能验证一次他们的产品,之后他们的代码将被验证从数据库中删除。我已经成功创建了“搜索”部分。当我尝试删除同一条记录时,它不起作用。我想在选择后立即删除。

请查看此代码并建议我如何删除该记录。我不是专业人士,只是初学者。

<?php
$produt_code = $_GET["product_code"];

$servername = "localhost";
$username = "#";
$password = "#";
$dbname = "#";

$conn = mysqli_connect($servername, $username, $password, $dbname);

if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}

$sql = "SELECT product_code FROM product_verify WHERE product_code=" . $_GET["product_code"];
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
echo '<font color="green"><h3>Congratulations!! You Have Genuine Product</h3></font>';

}
} else {
echo '<font color="red"><h3>Sorry!! You Dont Have A Genuine Product.</h3></font><br><font color="red"><h3>NOTE:</h3></font><font color="red"><h3>1.Please check for spelling mistakes and try again.</h3></font><font color="red"><h3>2.May be this product code is already verified.</h3></font>';

}
?>

我在 select 语句之后使用此代码

$sql2 = "DELETE FROM product_code WHERE product_code=" . $_GET["product_code"];
$result2 = mysqli_query($conn, $sql2);

但它没有删除该记录我尝试在 while 语句后发布相同的代码但没有用也尝试过这个

mysqli_query = "SELECT city_name,product_code FROM code_verify WHERE product_code=" . $_GET["product_code"];
$query = mysql_affected_rows();
if($query > 0)
{
$sql = "DELETE FROM product_code WHERE product_code=" . $_GET["product_code"];

但这都不起作用还尝试了另一个 php 在同一文件中删除

最佳答案

我会将删除查询放在 while 内:

if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
echo '<font color="green"><h3>Congratulations!! You Have Genuine Product</h3></font>';
$sql2 = "DELETE FROM product_code WHERE product_code=".$_GET['product_code'];
$result2 = mysqli_query($conn, $sql2);
}

这样,只有当您确定用户会收到反馈时,您才会执行查询。

关于mysql - 选择不起作用后删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30424738/

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