使用HTML输入类型'date'和'time'获取日期和时间,但不会使用PHP插入到mysql中

时间:2015-03-22 09:49:57

标签: php html mysql date time

第一次来这里很抱歉,如果我的格式错误!

我有一个createperform.php文件,它有一个链接回自身的表单。 performancedate和performancetime与prid for productionID一起发布。我有一个名为Performance的数据库表,它有4列(PerformanceID(Auto Inc,int),ProductionID(int),performancedate(date)& performancetime(time))

<form action="createperform.php" method="POST" role="form">
        <input type="date" required="required" name="performancedate" id="performancedate" />   
        <input type="time" required="required" name="performancetime" id="performancetime" />       
        <select name="prod">
            <?php
                while($row = $results->fetch_assoc())
                {
                    echo '<option value="' . $row['productionID'] . '">' . $row['productionname'] . '</option>';
                }
            ?>
        </select>               
        <br><br> 
        <button type="submit" value="Submit" name="submitPerform" class="btn btn-default">Create Performance</button>
    </form>

这是我在createperform.php顶部的PHP:

<?php 
session_start();
include("includes/adminheader.php");
include("db.php");

$results = $conn->query("SELECT * FROM Production");

if (isset($_POST["submitPerform"]))
{
    $performancedate = mysqli_real_escape_string($conn, $_POST["performancedate"]);
    $performancetime = mysqli_real_escape_string($conn, $_POST["performancetime"]).":00";
    $prodID = mysqli_real_escape_string($conn, $_POST["prod"]);

    $aresult = $conn->query("INSERT INTO Performance (productionID, performancedate, performancetime,)
    VALUES('{$prodID}','2015-06-23','02:34:24')");

    if ($aresult)
    {
        $message = "Performance successfully added to Production ID: ".$prodID;
    }   
    else
    {
        $message = "Performance failed to get added to Production ID: ".$prodID;
    }
}
?>

数据库连接在db.php中,我一直得到执行的if($ aresult)状态的else部分。我检查了我的表名,检查我的变量名,我没有得到任何错误。我确保日期格式为:YYYY-MM-DD并确保格式或时间为HH:MM:SS。

我打印出存储在日期和时间变量中的值,这就是我得到的:

<br><h3><?php echo $message; echo $performancedate; echo $performancetime;?></h3><br>
Performance failed to get added to Production ID: 52015-03-2923:54:00

我已经用尽了我现在可以尝试的东西。如果您还有其他需要,请告诉我。

0 个答案:

没有答案