2016-10-04 36 views
0

在我的插入活动出生日期没有插入到mysql数据库中插入所有其他其他记录插入但出生日期未插入。 下面是我的代码: GETDATE函数日期没有插入到android应用程序数据库中

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'])){ 

extract($ _ 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

任何你正在这里异常? – Chaitanya

+0

这里也不例外 –

+0

检查dateformat是否匹配 – Chaitanya

回答

0

使用下面的MySQL查询插入日期的Try ...

$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')";