2016-10-04 57 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')";