<?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代码段中,query1不起作用,而query 2很好。
我试图针对用户i / p(
dlkeuser(dislike)
)在$_GET["en"]
表中插入(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;
}
}