因此,我一直在尝试建立一个简单的网站,向MySQL上的数据库发送“喜欢”和“不喜欢”的信息。
根据开发人员网络标签,我不确定我的PHP文件是否已损坏,或者是否存在数据库问题,即请求确实连接。 (当我单击“不喜欢/喜欢”按钮时,请求会通过)
不确定要尝试什么。
if (isset($_POST['post_liked'])) {
$host = "ip";
$username = "admin";
$password = "";
$databasename = "likeanddislike";
$Connect = mysqli_connect($host, $username, $password);
mysqli_select_db($Connect, $databasename);
mysqli_query($Connect, "update rating_system set total_no_of_votes=total_no_of_votes+1,vote_likes=vote_likes+1");
$select = mysqli_query($Connect, "SELECT * FROM rating_system");
while ($row = mysqli_fetch_array($select, 1)) {
$total_no_votes = $row['total_no_of_votes'];
$liked = $row['vote_likes'];
$disliked = $row['vote_dislike'];
echo "<p id='total_rating'>Total Ratings ( " . $total_no_votes . " )</p>";
echo "<p id='total_like'><img src='attack.png'>" . $liked . "</p><div id='like_bar'></div>";
echo "<p id='total_dislike'><img src='attack.png'>" . $disliked . " </p><div id='dislike_bar'></div>";
exit();
}
}
if (isset($_POST['post_dislike'])) {
$host = "ip";
$username = "admin";
$password = "";
$databasename = "likeanddislike";
$connect = mysqli_connect($host, $username, $password);
mysqli_select_db($connect, $databasename);
mysqli_query($connect, "update rating_system set total_no_of_votes=total_no_of_votes+1,vote_dislike=vote_dislike+1");
$select = mysqli_query($connect, "SELECT * FROM rating_system");
while ($row = mysqli_fetch_array($select, 1)) {
$total_no_votes = $row['total_no_of_votes'];
$liked = $row['vote_likes'];
$disliked = $row['vote_dislike'];
echo "<p id='total_rating'>Total Ratings ( " . $total_no_votes . " )</p>";
echo "<p id='total_like'><img src='attack.png'>" . $liked . "</p><div id='like_bar'></div>";
echo "<p id='total_dislike'><img src='attack.png'>" . $disliked . " </p><div id='dislike_bar'></div>";
exit();
}
}
?>
对于HTML文件: Code