为什么android CheckBox值没有存储在MySQL中?

时间:2018-03-30 08:43:34

标签: php android

我制作了一个系统,我有多个CheckBox并使用排球将检查的值存储在 MySQL 数据库中,但是,数据库中没有显示任何值

下面是我的复选框代码:

if(checkBoxBus.isChecked()){
    checkbus = checkBoxBus.getText().toString();
}
if(checkBoxTrain.isChecked()){
    checktrain = checkBoxTrain.getText().toString();
}
if(checkBoxPrivateRickshaw.isChecked()){
    checkrickshaw = checkBoxPrivateRickshaw.getText().toString();
}
if(inputfrom.getEditText().equals("") || inputTo.getEditText().equals("") ||
            inputdescription.getEditText().equals("")){
    builder.setMessage("Please fill the information");
}

以下是排球的代码:

protected Map<String, String> getParams() throws AuthFailureError {
    Map<String,String> params = new HashMap<String, String>();
    params.put("from",from);
    params.put("to",to);
    params.put("travel_type",traveltype);
    params.put("workdescription",workdescription);
    params.put("passcheckbox",checktrain);
    params.put("trainpass",trainpass);
    params.put("passimage",passimage);
    params.put("transportmode",transportmode);
    params.put("payment",payment);
    params.put("finalamount",totalpayment);
    params.put("remaining_amount",remainingamount);
    return params;
}
};
Singleton.getInstance(MainActivity.this).addToREquestQueue(stringRequest);
}

除了复选框值之外,所有内容都会被存储起来,所以有人可以帮我解决我出错的问题

PHP代码

 <?php
include("conn.php");

$from = $_POST['from'];
$to = $_POST['to'];
$travel_type = $_POST['travel_type']; 
$workdescription = $_POST['workdescription'];
$passcheckbox = $_POST['passcheckbox'];
$trainpass = $_POST['trainpass'];
$buscheck = $_POST['buscheck'];
$image = $_POST['image'];
$name = $_POST['name'];
$rickshawcheck = $_POST['rickshawcheck'];
$transportmode = $_POST['transportmode'];
$payment = $_POST['payment'];
$finalamount = $_POST['finalamount'];
$remaining_amount = $_POST['remaining_amount'];

$response = array();
$sql = "INSERT INTO users2
    (arrival,destination,travel_type,work_description,'passcheckbox',train_pass,
    'buscheck',pass_image,'rickshawcheck',transport_mode,payment,total_amount,remaining_amount)
        VALUES
        ('$from','$to','$travel_type','$workdescription',$passcheckbox,'$trainpass','$buscheck','$name','$rickshawcheck','$transportmode','$payment','$finalamount','$remaining_amount');";
        $upload_path = "uploads/$name.jpg";
        file_put_contents($upload_path, base64_decode($image));
        if(mysqli_query($conn,$sql)){

        $code = "Your_data_has_been_submitted";
        array_push($response,array("code"=>$code));
        echo json_encode($response);
    }
?>
<!DOCTYPE html>
<html>  
<head>
    <title></title>
</head>
<body>
    <form method="post">
<input type="text" name="from">
<input type="text" name="to">
<input type="text" name="workdescription">
<input type="checkbox" name="passcheckbox">
<input type="text" name="trainpass">
<input type="checkbox" name="buscheck">
<input type="text" name="name">
<input type="file" name="image">
<input type="text" name="transportmode">
<input type="text" name="payment">
<input type="text" name="finalamount">
<input type="submit" name="btn_submit">
</form>
</body>
</html>

2 个答案:

答案 0 :(得分:0)

要读取复选框的值 - 请按照正确的android教程。

https://www.android-examples.com/how-to-get-checkbox-checked-value-in-android/

答案 1 :(得分:0)

//get the value
boolean checkbus = checkBoxBus.isChecked();

// in volley request                                     
params.put("passcheckbox",String.valueOf(checkbus));


//in log
Log.d(TAG,"checkbus" + String.valueOf(checkbus));

在php中,您忘记在数据库中插入checkvalue $passcheckbox $buscheck $rickshawcheck