php - 使用 PHP 编写程序时遇到问题

标签 php html mysql database xampp

我创建了两个表单,一个是注册表单,另一个是选择用户来和离开的日期。我在第二页中调用了用户的用户名..虽然我收到了它,但我收到一条消息“错误”,并且我的数据库上没有任何更新。这是我的第二页文件..我做错了什么?

<?php
session_start();
$EntryError=$ExitError="";
    if (isset($_POST['submit'])){
        $entrydate = $exitdate = "";
        $errorOccured = false;

        if (isset($_POST['tsmdate'])){
            $entrydate = trim($_POST['tsmdate']);
            if (strlen($entrydate) == 0){
                $EntryError = "date is missing";
                $errorOccured = true;
            }
        }
        else{
            $EntryError = "date is missing";
        }

        // checking for last name
        if (isset($_POST['tsmexit'])){
            $exitdate = trim($_POST['tsmexit']);
            if (strlen($exitdate) == 0){
                $ExitError = "First Name is missing";
                $errorOccured = true;
            }
        }
        else{
            $ExitError = "last Name is missing";
        }
        $ids=$_SESSION['tsmUserName'];
        var_dump($_SESSION);
        if(!$errorOccured){
            require_once("connection.php");
            $my_query="INSERT INTO timing (No, Entry Date and Time, Exit Date and Time, user_id) VALUES (NULL,'$EntryError','$exitdate','$ids')";
            $result=mysqli_query($connection,$my_query);
            if($result)
            {
                echo 'thank you';
            }
            else
            {
                echo 'error';
            }
            mysqli_close($connection);
        }
    }   
?>
<html>
<head>
</head>
<body>
<form name="dates" id="dates" method="POST" action="">
<table cellpadding="5" border="0" width="100%">
            <tr>
                <td colspan="3" align="center">
                <h1> select dates </h1>
                </td>
            </tr>

        <tr>
                <td width="30%" align="right">
                    <label for="tsmdate">Entry date and time</label>
                </td>
                <td align="left">
                    <input type="text" name="tsmdate" id="tsmdate" required="required">
                </td>
        </tr>
        <tr>
            <td width="30%" align="right">
                    <label for="tsmexit">Exit date and time</label>
                </td>
                <td align="left">
                    <input type="text" name="tsmexit" id="tsmexit" required="required">
                </td>
        </tr>

        <tr>
                <td colspan="2" align="center">
                    <input type="submit" name="submit" value="dates">
                </td>
            </tr>
        </table>
</form>
</body>
</html>

最佳答案

将 INSERT 查询更改为此

$my_query="INSERT INTO timing (`No`, `Entry Date and Time`, `Exit Date and Time`, `user_id`) VALUES (NULL,'$EntryError','$exitdate','$ids')";

确保任何数据库字段名称中是否有空格,那么它应该在`(后面的tic)内

关于php - 使用 PHP 编写程序时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41159737/

相关文章:

javascript - 用户输入后刷新 PHP 变量

javascript - 使用 jQuery 的 AJAX 调用中的 url 字段格式

html - 如何在移动方向更改时重置 Disqus 宽度

php - 将 datetime 转换为 varchar 从 MSSQL 到 MYSQL

javascript - 使用 jQuery 将变量传递给 .php

php - Mysql语法错误(我找不到错误是什么!)

javascript - 在 Chrome 和 Firefox 上获取 C9 应用程序的解析错误。不确定如何解决

javascript - 只给我点击样式的元素

php - 从 Wamp 文件夹恢复 MySQL 数据库

mysql - 在 MySQL 中,有没有办法在对列进行排序之前对其进行修改?