I have a little problem when i adding a checkbox in my app project, i hope when a checkbox selected or check, then it will be change to string and can be insert into mysql database. Any help would be appreciated. thank u.
Here my mainactivity code
private void addEmployee(){
final String nama = editTextName.getText().toString().trim();
final String pyg = editTextDesg.getText().toString().trim();
final String tmpt = editTextSal.getText().toString().trim();
final String tgl = Date.getText().toString().trim();
final String jam = Waktu.getText().toString().trim();
final Boolean email = Penting.isChecked();
class AddEmployee extends AsyncTask<Void,Void,String>{
ProgressDialog loading;
@Override
protected void onPreExecute() {
super.onPreExecute();
loading = ProgressDialog.show(MainActivity.this,"Menambahkan...","Tunggu...",false,false);
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
loading.dismiss();
Toast.makeText(MainActivity.this,s,Toast.LENGTH_LONG).show();
}
@Override
protected String doInBackground(Void... v) {
HashMap<String,String> params = new HashMap<>();
params.put(konfigurasi.KEY_EMP_NAMA,nama);
params.put(konfigurasi.KEY_EMP_PENYELENGGARA,pyg);
params.put(konfigurasi.KEY_EMP_TEMPAT,tmpt);
params.put(konfigurasi.KEY_EMP_TGL,tgl);
params.put(konfigurasi.KEY_EMP_JAM,jam);
params.put(konfigurasi.KEY_EMP_EMAIL, String.valueOf(email.equals("Penting")));
RequestHandler rh = new RequestHandler();
String res = rh.sendPostRequest(konfigurasi.URL_ADD, params);
return res;
and this my php code to insert into database
<?php
if($_SERVER['REQUEST_METHOD']=='POST'){
//Mendapatkan Nilai Variable
$nama = $_POST['nama'];
$desg = $_POST['pyg'];
$sal = $_POST['tmpt'];
$tgl = $_POST['tgl'];
$jam = $_POST['jam'];
$email = $_POST['email'];
//Pembuatan Syntax SQL
$sql = "INSERT INTO tb_pegawai (namaagenda,penyelenggara,tempat,tanggal,jam) VALUES ('$nama','$desg','$sal',str_to_date('".$tgl."', '%d-%m-%Y'),'$jam', '$email')";
//Import File Koneksi database
require_once('koneksi.php');
//Eksekusi Query database
if(mysqli_query($con,$sql)){
echo 'Berhasil Menambahkan Pegawai';
}else{
echo 'Gagal Menambahkan Pegawai';
}
mysqli_close($con);
}?>
Aucun commentaire:
Enregistrer un commentaire