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 = "";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行