我编写了一些代码来连接 MySQL 和 Web 服务器。这是我的代码
$dbusername = "root"; // enter database username, I used "arduino" in step 2.2
$dbpassword = "qonita84"; // enter database password, I used "arduinotest" in step 2.2
$server = "localhost"; // IMPORTANT: if you are using XAMPP enter "localhost", but if you have an online website enter its address, ie."www.yourwebsite.com"
// Connect to your database
$dbconnect = mysqli_connect($server, $dbusername, $dbpassword);
$dbselect = mysql_select_db("LTKA",$dbconnect);
// Prepare the SQL statement
$sql = "INSERT INT LTKA.angkot (RFID_ID, Saldo, KM) VALUES ('".$_GET["ID"]."','".$_GET["sisa"]."','".$_GET["naik"]."')";
// Execute SQL statement
mysql_query($sql);
?>
当我想使用 Google Chrome 将一些数据推送到数据库时,它总是显示此消息
localhost is currently unable to handle this request. HTTP ERROR 500
这是我在地址栏中输入的内容 https://localhost/write_data.php?ID=GH23658I&sisa=5000&naik=1
有人能给我解决办法吗?
答案1
此处的参数序列错误:
$con=mysqli_connect($mysql_host,$mysql_database,$mysql_user,$mysql_password);
查看消息:用户访问被拒绝'exuser'@'IP_Remote'
(使用密码:是),其中root
不是用户,而是您上面设置的数据库名称$mysql_database = "***********_people";.
解决方案:
$con=mysqli_connect($mysql_host, $mysql_user, $mysql_password, $mysql_database);
并授予用户权限:
GRANT ALL PRIVILEGES ON *.* TO exuser@'IP_REMOTE' IDENTIFIED BY 'Exuser2019!' with grant option;
flush privileges;