当我在phpmyadmin中执行语句时,它可以正常工作,但是当我将完全相同的查询复制并粘贴到这个php文件中时,它无法正常工作。
PHP代码:
if($_GET['vote'] == 1) {
echo "if statement ran";
$sql = "UPDATE raids SET attendees = attendees +1 WHERE dateposted = '2017-08-19 16:15:46'";
mysql_query($sql, $link);
}
我的链接变量确实有用,而且' if'语句执行。其他SQL语句没有给我带来麻烦。
为什么PHP代码不会增加'与会者'在PHP代码中使用时?
答案 0 :(得分:0)
正如Milan Chheda所说,MySQL已被弃用,不再安全。请改用PDO或至少使用MySQLi。
您的代码的MySQLi实现:
//MySQLi information
$db_host = "localhost";
$db_username = "username";
$db_password = "password";
//connect to mysqli database (Host/Username/Password)
$connection = mysqli_connect($db_host, $db_username, $db_password) or die("Error " . mysqli_error());
//select MySQLi dabatase table
$db = mysqli_select_db($connection, "table") or die("Error " . mysqli_error());
if(isset($_GET['vote']) && $_GET['vote'] !== NULL) {
$vote = $_GET['vote'];
if($vote == "1") {
echo "Vote is 1, updating the database";
$sql = mysqli_query($connection, "UPDATE raids SET attendees = attendees + '1' WHERE dateposted = '2017-08-19 16:15:46'");
}
}
我希望这有助于你。祝你好运!