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 は標準の接続文字列ファイルです。Footer.php は接続を閉じるだけです:) また、ob_start(); なしではコードを機能させることができませんでした。および終了関数:S
では、日付を日/月/年の形式で取得し、その方法で mysql に保存する方法を指摘できますか?