dqc2017
2016-09-28 16:21
浏览 31

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

I want create Android application, in my application I want send comment from app to server! For server side I write this code, but when running PHP code show me this error:

The site.com page isn’t working

site.com is currently unable to handle this request.
HTTP ERROR 500

For connect to the database I write this code:

<?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 ...";
    }
?>

When running this file (dbConnect.php) show me "Connection success ...".

For insert to the database I write below codes:

<?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);
    }

?>

Insert file name is (insertComment.php), when running this file (site.com/insertComment.php) show me this error!

The site.com page isn’t working

site.com is currently unable to handle this request.
HTTP ERROR 500

How can I fix it? I am amateur in PHP!

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongyu3967 2016-09-28 16:42
    已采纳

    The error 500 is due to a failure of PHP to parse successfully your code

    Replace

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

    With

    $comment_ID = "";
    ....
    $comment_type = "";
    
    已采纳该答案
    打赏 评论

相关推荐 更多相似问题