我需要一个关于从 php 表单向 mysql db 发送日期的小例子。尝试了很多例子,但我似乎错过了一步。我已经为 3 个字段准备了一个表格,即姓名和出生日期。当我填写表格并提交提交日期变得疯狂:) 0000-00-00 00:00:00
我试图格式化日期,但这次我不明白如何将它传递给 mysql。这是我有趣的代码;
<?php include "header.php" ?>
<?php include "conn.php" ?>
<script>
$(function() {
$( "#bdate" ).datepicker();
});
</script>
<?php
if(isset($_POST['submit'])){
$PlayerName = $_POST['PlayerName'];
$PlayerLname = $_POST['PlayerLname'];
$PlayerBdate = $_POST['PlayerBdate'];
$query = "INSERT INTO tblPlayer (
PlayerName, PlayerLname, PlayerBdate
) VALUES (
'{$PlayerName}', '{$PlayerLname}', '{$PlayerBdate}'
)";
if(mysql_query($query,$connection)){
//Sucess
header("Location: players_list.php");
} else{
echo "<p>something is wrong</p>";
echo "<p>" . mysql_error() . "</p>";
}
}
?>
<form action="add_player.php" method="post">
<table>
<tr>
<td>Name: </td>
<td><input type="text" name="PlayerName" /></td>
</tr>
<tr>
<td>Lastname:</td>
<td><input type="text" name="PlayerLastName" /></td>
</tr>
<tr>
<td>Birthdate:</td>
<td><input id="bdate" type="text" name="PlayerBdate" /></td>
</tr>
<tr>
<td><input type="submit" name="submit" value="Save" /></td>
<td align="right"> </td>
</tr>
</table>
<?php ob_end_flush() ?>
<?php include ("footer.php") ?>
header.php 包含
<?php ob_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>
<title>Untitled Document</title>
</head>
<body>
conn.php 是标准连接 sting 文件。Footer.php 只是关闭连接:) 另外,如果没有 ob_start(); ,我也无法使我的代码工作。和结束功能:S
那么你能指出我如何以日/月/年格式获取日期并将其保存到 mysql 中吗?