加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
dislike.php 1.33 KB
一键复制 编辑 原始数据 按行查看 历史
陌谦 提交于 2018-12-15 20:40 . 1
<?php $name = $_POST["data"];
?>
<?php
$localhost = 'localhost';
$user = 'root';
$password = 'gis502@hm';
$dbname = 'likes';
$connect = new mysqli();
$connect->connect($localhost, $user, $password, $dbname);
$connect->query("set character set 'utf8'");
if ($connect->connect_error) {
die('connection failed') . $connect->connect_error; //连接数据库
}
// $slect = "SELECT names FROM thumbsup"; //从thumbsup表中选取name列
// $result = $connect->query($slect); //取出选取结果
// if ($result->num_rows > 0) {
// // 输出每行数据
// while ($row = $result->fetch_assoc()) {
// echo "<br> name: " . $row["names"];
// };
// } else {
// echo "0 results";
// }
$check = $connect->query("SELECT*FROM thumbsup WHERE names='$name'");
while ($check->num_rows == 0) {
$insert = $connect->query("INSERT INTO thumbsup (names)
VALUES('$name')");
$check = $connect->query("SELECT*FROM thumbsup WHERE names='$name'");
}
$row = mysqli_fetch_assoc($check);
$likesCount=$row['likes'];
if($likesCount==null){
$refill=$connect->query("UPDATE thumbsup SET likes='0' WHERE names='$name'");
}
else{
$addLikesCount=$likesCount-1;
$add=$connect->query("UPDATE thumbsup SET likes='$addLikesCount' WHERE names='$name'");
$likesCount=$row['likes'];
}
// $likesCount=(int)$likesCount;
echo($likesCount-1);
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化