我想创建 Android 应用程序,在我的应用程序中我想将评论从应用程序发送到服务器!对于服务器端,我编写了此代码,但是在运行 PHP 代码时显示此错误:
The site.com page isn’t working
site.com is currently unable to handle this request.
HTTP ERROR 500
对于连接到数据库,我编写了以下代码:
<?php
define('HOST', 'localhost');
define('USER', 'userName');
define('PASS', 'password');
define('DB', 'databseName');
$con = mysqli_connect(HOST, USER, PASS, DB);
if($con){
echo "Connection success ...";
} else {
echo "Connection Failed ...";
}
?>
运行此文件 (dbConnect.php) 时,显示“连接成功...”
。
对于插入数据库,我编写以下代码:
<?php
require "dbConnect.php";
$comment_ID = ;
$comment_post_ID = 2289;
$comment_author = "test name";
$comment_author_email = "emailTest@gmail.com";
$comment_author_url = "";
$comment_author_IP = 0;
$comment_date = 2016-09-28;
$comment_date_gmt = 2016-09-28;
$comment_content = "This is one test comment with PHP code";
$comment_karma = 0;
$comment_approved = 0;
$comment_agent = "";
$comment_type = ;
$comment_parent = 0;
$user_id = 0;
$sql_query = "INSERT INTO qpHskU_comments VALUES ('$comment_ID', '$comment_post_ID', '$comment_author', '$comment_author_email',
'$comment_author_url', '$comment_author_IP', '$comment_date', '$comment_date_gmt', '$comment_content',
'$comment_karma', '$comment_approved', '$comment_agent', '$comment_type', '$comment_parent', '$user_id');";
if(mysqli_query($con,$sql_query)){
echo "Record added successfully.";
} else {
echo "Record not added..." . mysqli_error($con);
}
?>
插入文件名为 (insertComment.php),运行此文件 (site.com/insertComment.php) 时显示此错误!
The site.com page isn’t working
site.com is currently unable to handle this request.
HTTP ERROR 500
我该如何解决这个问题?我对 PHP 是业余爱好者!
最佳答案
错误 500 是由于 PHP 无法成功解析您的代码
替换
$comment_ID = ;
....
$comment_type = ;
与
$comment_ID = "";
....
$comment_type = "";
关于php - 如何修复PHP插入数据时的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39752834/