select 无效后删除
Delete after select not working
在这个网站上我正在开发一个正版产品代码验证系统,所以当用户在表单中插入代码时,这将向他们显示他们的产品是否是正品,但用户只能在他们的代码之后验证他们的产品一次将从数据库中删除。我已成功创建 "search" 部分。当我试图删除同一条记录时,它不起作用。我想在 select 之后删除。
请查看此代码并建议我如何删除该记录。
我不是专业人士,只是初学者。
<?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 删除同一文件
首先不要在 PHP 标签中使用 "query"."variable",所以删除它并替换它
$sql = "SELECT product_code FROM product_verify WHERE product_code = $_GET["product_code"]";
第二件事从 echo 的外侧删除单引号并在外侧使用 "" 双引号并在双引号内使用单引号 ''。
echo "
恭喜!!您拥有正品
";
我会将删除查询放在 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);
}
这样,只有当您确定用户会得到反馈时,您才会执行查询。
在这个网站上我正在开发一个正版产品代码验证系统,所以当用户在表单中插入代码时,这将向他们显示他们的产品是否是正品,但用户只能在他们的代码之后验证他们的产品一次将从数据库中删除。我已成功创建 "search" 部分。当我试图删除同一条记录时,它不起作用。我想在 select 之后删除。
请查看此代码并建议我如何删除该记录。 我不是专业人士,只是初学者。
<?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 删除同一文件
首先不要在 PHP 标签中使用 "query"."variable",所以删除它并替换它
$sql = "SELECT product_code FROM product_verify WHERE product_code = $_GET["product_code"]";
第二件事从 echo 的外侧删除单引号并在外侧使用 "" 双引号并在双引号内使用单引号 ''。
echo "
恭喜!!您拥有正品
";我会将删除查询放在 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);
}
这样,只有当您确定用户会得到反馈时,您才会执行查询。