dongshanyan0322 2015-03-22 09:49
浏览 31

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

First time on here so sorry if I get the formatting wrong!

I have a createperform.php file which has a form that links back to itself. The performancedate and performancetime is posted along with the prod for productionID. I have a database Table called Performance, which has 4 columns (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>

Here is my PHP at the top of the createperform.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;
    }
}
?>

The db connection is in db.php, I keep getting the else part of the if($aresult) state that executes. I have checked my table names, check my variable names, I am getting no errors at all. I made sure that the format of the date is: YYYY-MM-DD and made sure that the format or the time is HH:MM:SS.

I printed out the values stored in the date and time variables and this is what I got:

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

I have ran out of things that I can try now. If you need anything else let me know.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 划分vlan后不通了
    • ¥15 GDI处理通道视频时总是带有白色锯齿
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)
    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制
    • ¥15 merge函数占用内存过大
    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大