从Php插入日期

从Php插入日期,php,date,content-management-system,Php,Date,Content Management System,我在我的CMS中有一个文本字段,在这里我可以添加最后的比赛结果并将其发布到数据库中。我唯一缺少的是,需要帮助的是如何添加此日期。例如,曼联的最后一场比赛是在6月12日星期二。我想把那个日期放在我的CMS和数据库里。我该怎么做?这是我的密码 <body> <form action="index.php?insert_last_game" method="post"> <table width="795" align="center" bgcolor="#FF

我在我的CMS中有一个文本字段,在这里我可以添加最后的比赛结果并将其发布到数据库中。我唯一缺少的是,需要帮助的是如何添加此日期。例如,曼联的最后一场比赛是在6月12日星期二。我想把那个日期放在我的CMS和数据库里。我该怎么做?这是我的密码

<body>
<form action="index.php?insert_last_game" method="post"> 
    <table width="795" align="center" bgcolor="#FFFFFF">
        <tr bgcolor="#FF6600">
            <td colspan="6" align="center"><h1>Insert Last Game:</h1></td>
        </tr>
        <tr>
            <td align="right" bgcolor="#FF6600"><strong>Game:</strong></td>
            <td><input type="text" name="game" size="60"/></td>
        </tr>
        <tr>
            <td align="right" bgcolor="#FF6600"><strong>Game:</strong></td>
            <td><input type="text" name="date" size="60"/></td>
        </tr>
        <tr bgcolor="#FF6600">
            <td colspan="6" align="center"><input type="submit" name="submit" value="Publish Now"/></td>
        </tr>
    </table>
</form>

插入最后一个游戏:
游戏:
游戏:

和我的php部分。

<?php 
include("connect.php");
if(isset($_POST['submit'])){
$post_game = $_POST['game'];
$post_date = date('d-m-y');
if($post_game==''){
echo "<script>alert('Please fill in all fields')</script>";
exit();
}
else {
$insert_game = "insert into last_game (game,date) values ('$post_game','$post_date')";
$run_posts = mysqli_query($con,$insert_game); 
echo "<script>alert('Post Has been Published!')</script>";
echo "<script>window.open('index.php?insert_last_game','_self')</script>";
}
}
?> 

首先,在HTML中,您将第二个标签命名为Game,而不是date

<td align="right" bgcolor="#FF6600"><strong>Game:</strong></td>
剩下的你都已经做了

如果您希望将日期格式化为6月12日星期二,您可以这样做:

$post_date = date('D, jS', $time) . ' of ' . date('F', $time);
另外,祝贺您使用了
mysqli\uu
addwithstrotime,请参阅

显示日期,例如:

$test = strtotime("now");
echo date("jS F, Y", $test); 

谢谢你,先生。它正在工作。如果我想将日期存储为2016年6月12日,该怎么办?。我应该把日期('d-m-y')改成其他格式,对吗?是的,日期('d-m-y')是您使用的格式。您可以在此处看到所有格式:
$test = strtotime("now");
echo date("jS F, Y", $test);