0

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!

Sauced Apples
  • 1,163
  • 2
  • 14
  • 37
  • Find your error logs and read'em. – u_mulder Sep 28 '16 at 16:22
  • `$comment_date = 2016-09-28;` is not a date btw. – u_mulder Sep 28 '16 at 16:23
  • ^ being an equivalent to an sql injection along with the other one. – Funk Forty Niner Sep 28 '16 at 16:24
  • @u_mulder, how can I fix it my friend? I write php codes in NOTEPAD++ and in this editor not show error :( . how can I fix it? –  Sep 28 '16 at 16:25
  • @Fred-ii-, I am not time my friend :( can you help me for this error? please , please –  Sep 28 '16 at 16:26
  • you have "no time" you say? – Funk Forty Niner Sep 28 '16 at 16:26
  • add `""` around each of your `$comment_` vars should fix it. – Proger_Cbsk Sep 28 '16 at 16:28
  • @Fred-ii-, my mean is I'm not time for learn :( . I should send this project fastly for my prof ! and my problem just here :( –  Sep 28 '16 at 16:28
  • @Proger_Cbsk, can you send me your mean with code? please –  Sep 28 '16 at 16:29
  • @Proger_Cbsk, `$comment_ID` is AUTOINCREMENT ! and fill automatically –  Sep 28 '16 at 16:31
  • Do not `$comment_ID = ;` but `$comment_ID = "";` , also not `$comment_date = 2016-09-28;` but `$comment_date = "2016-09-28";` etc... – Proger_Cbsk Sep 28 '16 at 16:31
  • First let's fix your error 500, then fix your SQL wrongness, mind you ? – Proger_Cbsk Sep 28 '16 at 16:32
  • @Proger_Cbsk, thanks man, but this values is INT. I should set "" for int values?! –  Sep 28 '16 at 16:32
  • **throws hands in the air** Is this entire site just helping kids do their homework now? It's like no one reads the manual and tries to troubleshoot code on their own. – Blake Sep 28 '16 at 16:33
  • @Proger_Cbsk, thanks man, when added "" this error hide and added successfully <3. but this values is INT why we should "" ?! "" for string! –  Sep 28 '16 at 16:34
  • since you're not doing math with those value but using them into a string, INT or not doesnt matter. – Proger_Cbsk Sep 28 '16 at 16:35
  • Your error 500 is fixed, good. As Blake said, i'll not do your homework : there is many error and misunderstood concept in your code that you'll have to fix yourself. – Proger_Cbsk Sep 28 '16 at 16:37
  • @Proger_Cbsk, Thank you my dear friend for you help and time <3 . please add your help in answer this question and I accept it. perhaps help another mans :) –  Sep 28 '16 at 16:38
  • @Proger_Cbsk, how can fix my other error?! or good performance ?! can you send me link for read? or send code? –  Sep 28 '16 at 16:40
  • For the auto_increment : http://stackoverflow.com/questions/7492145/php-mysql-insert-new-record-into-table-with-auto-increment-on-primary-key – Proger_Cbsk Sep 28 '16 at 16:44
  • @Proger_Cbsk, thank you my friend –  Sep 28 '16 at 16:48
  • @Proger_Cbsk, can you help me for this topic? : http://stackoverflow.com/questions/39754474/how-to-insert-utf-8-characters-from-php-into-database –  Sep 28 '16 at 18:18

1 Answers1

1

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 = "";
Proger_Cbsk
  • 362
  • 3
  • 12