在我的插入活动出生日期未插入mysql数据库中所有其他记录都插入但未插入出生日期。 以下是我的代码: getDate函数
private void getDate() {
final Calendar c = Calendar.getInstance();
mYear = c.get(Calendar.YEAR);
mMonth = c.get(Calendar.MONTH);
mDay = c.get(Calendar.DAY_OF_MONTH);
DatePickerDialog datePickerDialog = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
et_dob.setText(dayOfMonth + "-" + (monthOfYear + 1) + "-" + year);
}
}, mYear, mMonth, mDay);
datePickerDialog.show();
params
Map<String,String> params = new HashMap<String,String>();
params.put(KEY_NAME,et_first_name.getText().toString());
params.put(KEY_MIDDLE_NAME,et_middle_name.getText().toString());
params.put(KEY_LAST_NAME,et_last_name.getText().toString());
params.put(KEY_DOB,et_dob.getText().toString());
// Log.d("mytag", "dob" + et_dob.getText().toString());
params.put(KEY_CITY,et_city.getText().toString());
params.put(KEY_GENDER,gender);
params.put(KEY_STATE,et_state.getText().toString());
return params;
的onCreate
et_first_name = (EditText) findViewById(R.id.et_first_name);
et_middle_name = (EditText) findViewById(R.id.et_middle_name);
et_last_name = (EditText) findViewById(R.id.et_last_name);
et_dob = (EditText) findViewById(R.id.et_dob);
et_state = (EditText) findViewById(R.id.et_state);
et_city = (EditText) findViewById(R.id.et_city);
rdb_1= (RadioButton) findViewById(R.id.rd_male);
rdb_2= (RadioButton) findViewById(R.id.rd_female);
日期的xml
<EditText
android:layout_width="match_parent"
android:hint="Choose Date"
android:layout_height="wrap_content"
android:id="@+id/et_dob"
android:inputType="date"
android:padding="20dp"
android:layout_centerVertical="true"
android:layout_alignLeft="@+id/etTime"
android:layout_alignStart="@+id/etTime" />
insert.php
if (isset($_POST['user_first_name'])&&($_POST['user_middle_name'])&&($_POST['user_last_name']) && ($_POST['user_date_of_birth'])&&($_POST['user_gender'])&& ($_POST['user_state'])&&($_POST['user_city'])){
提取物($ _ POST);
$string_query="INSERT INTO `tbl_user`
(`user_first_name`,`user_middle_name`,`user_last_name`,`user_date_of_birth`,`user_gender`,`user_state`,`user_city`)
VALUES
('$user_first_name','$user_middle_name','$user_last_name','$user_date_of_birth','$user_gender','$user_state','$user_city')";
当我尝试插入日期0000-00-00
时,会将其插入数据库中
任何建议都是受欢迎的。
答案 0 :(得分:0)
尝试使用下面的mysql查询来插入日期......
$string_query="INSERT INTO `tbl_user`
(`user_first_name`,`user_middle_name`,`user_last_name`,`user_date_of_birth`,`user_gender`,`user_state`,`user_city`)
VALUES
('$user_first_name','$user_middle_name','$user_last_name', date('Y-m-d', strtotime($user_date_of_birth)),'$user_gender','$user_state','$user_city')";