connect_errno . ") " . -6ren">
gpt4 book ai didi

php删除sql查询不起作用

转载 作者:行者123 更新时间:2023-11-29 19:10:47 25 4
gpt4 key购买 nike

<?php
include('session.php');
?>

<?php
$conn = new mysqli("127.0.0.1","root","","foo");
if ($conn->connect_errno) {
echo "Failed to connect to MySQL: (" . $conn->connect_errno . ") " . $conn->connect_error;
}
$sew = $_SESSION['login_user'];
$a = $_GET["en"];
$l = 1;
$d = -1;

if($a == 1)
{
$sqlw = " INSERT into dlkeuser VALUES('$a','$sew')" ;

if ($conn->query($sqlw) === FALSE)
{
echo "you have already disliked the song";
}
else
{
//query1
$sql = " DELETE FROM lkeuser WHERE userid = '$sew' AND songid = '$a' ";

//query2
$sql = "UPDATE liking
SET count = count - 1 ";

if ($conn->query($sql) === TRUE) {
echo "you disliked the song";
}
else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}

在此 PHP 代码片段中,查询 1 不起作用,而查询 2 则正常。

我正在尝试根据用户 i/p($_GET["en"]) 在 dlkeuser(dislike) 表中插入 (songid, userid) 并删除从 lkeuser(like) 表记录(songid,userid)(如果存在)。 (songid,userid) 对是这里的复合主键。 count 是对歌曲的净喜欢/不喜欢。

最佳答案

让我们试试这个,

它会起作用

<?php
include('session.php');
?>

<?php
$conn = new mysqli("127.0.0.1","root","","foo");
if ($conn->connect_errno) {
echo "Failed to connect to MySQL: (" . $conn->connect_errno . ") " . $conn->connect_error;
}
$sew = $_SESSION['login_user'];
$a = $_GET["en"];
$l = 1;
$d = -1;

if($a == 1)
{
$sqlw = " INSERT into dlkeuser VALUES('$a','$sew')";

if ($conn->query($sqlw) === FALSE)
{
echo "you have already disliked the song";
}
else
{
//query1
$sql = " DELETE FROM lkeuser WHERE userid = '$sew' AND songid = '$a' " ;

//query2
$sql1 = "UPDATE liking
SET count = count - 1 ";

if ($conn->query($sql) === TRUE) {
echo "deleted the song";
}

if ($conn->query($sql1) === TRUE) {
echo "you disliked the song";
}
else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}

关于php删除sql查询不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43098750/

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