0

私はこれが初めてですが、データベースに新しい値を挿入しようとすると、php コードが null 値を返すという問題があります。

私のphpコード:

<?php

require("db_connect.php");

if (!empty($_POST)) {

//initial query

$query = "INSERT INTO examclaims ( Trainee_Name, Department, Trainee_ID, Batch_ID, Exam_ID, Attempts, Exam_Date, Invoice_no, Invoice_Date, BeforeGST, GST, AFTERGST)
 VALUES ( :Trainee_Name, :Department, :Trainee_ID, :Batch_ID, :Exam_ID, :Attempts, :Exam_Date, :Invoice_no, :Invoice_Date, :BeforeGST, :GST, :AFTERGST) ";

//Update query
$query_params = array(
    ':Trainee_Name' => $_POST['traineename'],
    ':Department' => $_POST['departmentname'],
    ':Trainee_ID' => $_POST['traineeid'],
    ':Batch_ID' => $_POST['batchid'],
    ':Exam_ID' => $_POST['examid'],
    ':Attempts' => $_POST['attempted'],
    ':Exam_Date' => $_POST['examdate'],
    ':Invoice_no' => $_POST['invoiceno'],
    ':Invoice_Date' => $_POST['invoicedate'],
    ':BeforeGST' => $_POST['beforegst'],
    ':GST' => $_POST['gst'],
    ':AFTERGST' => $_POST['aftergst'],
);

try {
    $stmt   = $db->prepare($query);
    $result = $stmt->execute($query_params);

}

catch (PDOException $ex) {
    $response["success"] = 0;
    $response["message"] = "Database Error. Couldn't add post!";
    die(json_encode($response));
}

$response["success"] = 1;
$response["message"] = "Username Successfully Added!";
echo json_encode($response);
} else {

?>
    <h1>Add Comment</h1>
    <form action="ExamClaims.php" method="post">
        name:<br />
        <input type="text" name="traineename" placeholder="name" />
        <br /><br />
        Department:<br />
        <input type="text" name="departmentname" placeholder="post department" />
        <br /><br />
        Message:<br />
        <input type="text" name="traineeid" placeholder="post trainee id" />
        <br /><br />
        <input type="text" name="batchid" placeholder="post batchid" />
        <br /><br />
        <input type="text" name="examid" placeholder="post examid" />
        <br /><br />
        <input type="text" name="attempted" placeholder="post attempted" />
        <br /><br />
        <input type="text" name="examdate" placeholder="post examdate" />
        <br /><br />
        <input type="text" name="invoiceno" placeholder="post invoiceno" />
        <br /><br />
        <input type="text" name="invoicedate" placeholder="post invoice date" />
        <br /><br />
        <input type="text" name="beforegst" placeholder="post before" />
        <br /><br />
        <input type="text" name="gst" placeholder="post gst" />
        <br/><br/>
         <input type="text" name="aftergst" placeholder="post after" />
        <br /><br />
        <input type="submit" value="Submit" />
    </form>
<?php
}
?>

私のアンドロイドコード:

class SubmitClaims extends  AsyncTask<String, String, String> {

    @Override
    protected String doInBackground(String... arg0) {
        // TODO Auto-generated method stub
            String traineeName = traineename.getText().toString();
            String Department = departmentname;
            String Traineeid = traineeid.getText().toString();
            String Batchid = batchid.getText().toString();
            String ExamID = examid.getText().toString();//attempts
            String Attempts = attempted;
            String Exam_date = examdate;
            String Invoice_no =invoiceno.getText().toString();
            String Invoice_date = invoicedate;
            String BGST = beforegst.getText().toString();
            String GST = gst.getText().toString();
            String AGST = aftergst.getText().toString();
            try {
                // Building Parameters
                List<NameValuePair> params = new ArrayList<NameValuePair>();
                params.add(new BasicNameValuePair("traineename", traineeName));
                params.add(new BasicNameValuePair("departmentname", Department));
                params.add(new BasicNameValuePair("traineeid", Traineeid));
                params.add(new BasicNameValuePair("batchid", Batchid));
                params.add(new BasicNameValuePair("examid",ExamID));//attmempts
                params.add(new BasicNameValuePair("attempted",Attempts));//attmempts
                params.add(new BasicNameValuePair("examdate" ,Exam_date));
                params.add(new BasicNameValuePair("invoiceno", Invoice_no));
                params.add(new BasicNameValuePair("invoicedate", Invoice_date));
                params.add(new BasicNameValuePair("beforegst",  BGST)); 
                params.add(new BasicNameValuePair("gst",  GST)); 
                params.add(new BasicNameValuePair("aftergst",  AGST)); 

               Log.d("request!", "starting");

                JSONObject json = jsonParser.makeHttpRequest(ExamClaims_URL, "POST", params);   

                            // Async json success tag
                            int success = json.getInt(TAG_SUCCESS);
                            if (success == 1) {
                                Log.d("Submitted", json.toString());
                                finish();                                   
                                return json.getString(TAG_MESSAGE);
                            } else {
                                Log.d("Fail to Submit!", json.getString(TAG_MESSAGE));
                                return json.getString(TAG_MESSAGE);
                            }

            } catch (JSONException e) {
                e.printStackTrace();
            }
        return null;
    }   

 }

このコードの問題は何ですか?? 助けてください、事前に感謝します

4

1 に答える 1

0

PHPコードがnull値を送信している場合のトレイルとエラーのデバッグ..

nullで0を意味していると思いますか?

あなたのコードがここで壊れていると思うからですか?

catch (PDOException $ex) {
    $response["success"] = 0;
    $response["message"] = "Database Error. Couldn't add post!";
    die(json_encode($response));
}
于 2013-08-05T12:23:17.970 に答える