在数据库中存储日期选择器值

时间:2017-09-16 19:17:05

标签: php database date datepicker insert

我正在尝试将日期选择器的值存储在我的数据库中。到目前为止,我已经能够存储其他值,但不能存储日期选择器值。

形式:

import static org.junit.Assert.assertArrayEquals;
import org.junit.Test;

public class CryptoUtilsTest {

  /**
   * Byte array to test encoding.
   * 
   * @see https://stackoverflow.com/questions/1301402/example-invalid-utf8-string
   */
  private static final byte[] ENCODE_TEST_ARRAY = new byte[] { (byte) 0x00,
    (byte) 0x00, (byte) 0x0a, (byte) 0x0c, (byte) 0x0d, (byte) 0xc3,
    (byte) 0x28, (byte) 0x7f, (byte) 0x80, (byte) 0xfe, (byte) 0xff };

  public void encoderDecoderTest(Encoder encoder, Decoder decoder) {
    String encoded = encoder.apply(ENCODE_TEST_ARRAY);
    byte[] decoded = decoder.apply(encoded);
    assertArrayEquals("encoder \"" + encoder.getClass() + "\" / decoder \""
        + decoder.getClass() + "\" failed!", ENCODE_TEST_ARRAY, decoded);
  }

  /**
   * Shows that String(byte[] encrypted).getBytes() does not return encrypted
   * for all input, as some byte sequences can't be interpreted as a string as
   * there are bytes/sequences that just don't represent characters!           
   */
  @Test
  public void testSimpleEncoder() {
    Encoder encoder = new CryptoUtils.EncoderNotWorking();
    Decoder decoder = new CryptoUtils.DecoderNotWorking();
    encoderDecoderTest(encoder, decoder);
  }

  /**
   * Shows that encoding a byte array into a String interpreting it as Latin1
   * should work.
   */
  @Test
  public void testLatin1Encoder() {
    Encoder encoder = new CryptoUtils.EncoderLatin1();
    Decoder decoder = new CryptoUtils.DecoderLatin1();
    encoderDecoderTest(encoder, decoder);
  }

  /** Shows that Base64 encoder should be used to encode random byte arrays. */
  @Test
  public void testBase64Encoder() {
    Encoder encoder = new CryptoUtils.EncoderBase64();
    Decoder decoder = new CryptoUtils.DecoderBase64();
    encoderDecoderTest(encoder, decoder);
  }
}

要插入数据库的代码:

                  <form class="form-signin" name="Register_Form" method="post" action="regcheck.php">
                    <h2 class="form-signin-heading">Please sign in</h2>

                    <label for="SecondName" class="sr-only">Second Name</label>
                    <input type="SecondName" id="SecondName" name="SecondName" class="form-control" placeholder="Second Name" required>

                    <div class="input-group input-append date" id="dateRangePicker"> <!-- Date input -->
                        <label for="Course" class="sr-only">Date</label>
                   <input class="form-control" id="date" name="date" placeholder="MM/DD/YYYY" type="text" />
                        <span class="input-group-addon add-on"><span class="glyphicon glyphicon-calendar"></span></span>
                    </div>

                    <button class="btn btn-lg btn-primary btn-block" type="reg" name="reg" value="Register">Register</button>
                  </form>

2 个答案:

答案 0 :(得分:0)

DB中的DOB字段是什么格式? 如果是时间戳,那么你需要做

<configuration-component> </configuration-component>

如果是约会,那么你需要做

$dob = strtotime($_POST['date']);

如果是日期时间,那么你需要做

$dob = date('Y-m-d', strtotime($_POST['date']));

答案 1 :(得分:0)

在mysql日期类型中,您无法存储MM/DD/YYYY之类的日期,您必须将日期格式更改为YYYY-MM-DD。改变输入,如

$dob = date('Y-m-d', strtotime($_POST['date']));