插入数据时如何修复PHP错误

时间:2016-09-28 16:21:38

标签: php android mysql

我想创建Android应用程序,在我的应用程序中我想从app发送评论到服务器!对于服务器端我编写此代码,但运行 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 )时,请显示"Connection success ..."

对于插入数据库,我写下以下代码:

<?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的业余爱好者!

1 个答案:

答案 0 :(得分:1)

错误500是由于PHP无法成功解析您的代码

替换

$comment_ID = ;
....
$comment_type = ;

使用

$comment_ID = "";
....
$comment_type = "";
相关问题