代码拉取完成,页面将自动刷新
<?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);
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。