【问题标题】:date not inserted in database of android application日期未插入 android 应用程序的数据库
【发布时间】:2016-10-04 06:42:28
【问题描述】:

在我的插入活动中,未将出生日期插入 mysql 数据库中,所有其他记录均已插入,但未插入出生日期。 以下是我的代码: 获取日期函数

  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();

参数

 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" />

插入.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 时,它被插入到数据库中 欢迎提出任何建议。

【问题讨论】:

  • 这里有什么异常吗?
  • 这里也不例外
  • 检查日期格式是否匹配

标签: php android mysql json


【解决方案1】:

尝试使用下面的 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')";

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-15
    • 2019-06-14
    • 2013-08-16
    • 2014-10-03
    • 1970-01-01
    相关资源
    最近更新 更多