mysql phpmyadmin,如何保存通过输入类型“select”(下拉)的表单获得的出生日期

发布于 2024-09-03 16:13:05 字数 247 浏览 1 评论 0原文

我有一个表格询问用户的出生日期。由于我使用选择输入类型,因此它是一个下拉框。第一个下拉菜单有“月”,第二个下拉菜单有“天”,第三个下拉菜单有“年”。因此格式应为月(10 月)、日(25)、年(1990)。换句话说,月份说明了实际的月份,而不仅仅是月份的数字表示。但是,我想以各自的格式保存日期和年份。我如何在 phpMyAdmin 中执行此操作?我应该使用 DATE 类型吗?该值应该是多少?我只需要知道如何在 phpmyadmin 中关联所有这些,这样我就可以正确保存它。谢谢。

I have a form which asks the user his or her date of birth. Its a drop down box since I use the select input type. The first drop down has Months, second has Days, the third has the Years. So the format should be Month(October), Day(25), Year(1990). In other words the months spell out the actual month and not simply the number representation of the month. However, I would like to save the Day and Year in their respective formats. How can I do this in phpMyAdmin? Should I use the DATE type? what should the value be? I just need to know how to correlate all of this in phpmyadmin, so I can save it properly. Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

空城仅有旧梦在 2024-09-10 16:13:05

我应该使用 DATE 类型吗?

,以下是如何连接它们并将其存储在数据库中:

$month = $_POST['month'];
$day = $_POST['day'];
$year = $_POST['year'];

$date = $month . '-' . $day . '-' . $year;

现在,您可以在查询中针对 date 使用 $date 变量类型字段。

Should I use the DATE type?

Yes and here is how you can concatenate them and store in the database:

$month = $_POST['month'];
$day = $_POST['day'];
$year = $_POST['year'];

$date = $month . '-' . $day . '-' . $year;

Now you can use the $date variable in your query against the date type field.

梦断已成空 2024-09-10 16:13:05

我希望不是 phpmyAdmin 而是 mysql。

那么,您必须区分事物的价值和它的表示
虽然值可以始终相同,但表示形式可能会有所不同。

在MySQL中存储日期的唯一方法是将其存储在日期字段中,该字段具有严格的格式:

YYYY-MM-DD

并且您只能以这种格式存储日期。
为此,您必须像这样选择月份:

<select name="month">
  <option value="1">January</option>
  <option value="2">February</option>
  ...
</select>

因此,月份将用单词表示,而数值将发送到服务器。
现在,您可以与日期和年份变量一起组合一个日期字符串:

$date = $_POST['year']."-". $_POST['month']."-".$_POST['day'];
$date = mysql_real_escape_string($date);

现在您已准备好将日期存储在数据库中。

Not phpmyAdmin but mysql you mean I hope.

Well, you have to distinguish the value of the thing and it's representation.
While value can be always the same, representation may vary.

The only way to store date in MySQL is to store it in the date field, which has strict format:

YYYY-MM-DD

And you have to store your date in this format only.
To do this, you have to make your month select like this:

<select name="month">
  <option value="1">January</option>
  <option value="2">February</option>
  ...
</select>

So, month will be represented with word, while numeric value will be sent to the server.
Now, along with day and year variables, you can assemble a date string:

$date = $_POST['year']."-". $_POST['month']."-".$_POST['day'];
$date = mysql_real_escape_string($date);

Now you have your date ready to store in the database.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文