SQL语法错误检查与MariaDB服务器版本对应的手册,以便在附近使用正确的语法

时间:2018-05-08 17:24:37

标签: php mysql

我试图使用php表单将行插入到mysql数据库中,但无法弄清楚为什么我会收到此错误:

Error: INSERT INTO time ('emp_name', 'clockdate', 'start_at', 'end_at') VALUES ('John Smith','2018-05-01','08:00:00','12:00:00') You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''emp_name', 'clockdate', 'start_at', 'end_at') VALUES ('John Smith','2018-05-01' at line 1

这是我的代码:

    $conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$sql = "INSERT INTO time ('emp_name', 'clockdate', 'start_at', 'end_at')
VALUES ('".$_POST["Name"]."','".$_POST["Date"]."','".$_POST["Start"]."','".$_POST["End"]."')";

if ($conn->query($sql) === TRUE) {
    echo "New record created successfully";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();
?>

我的HTML:

<form action="connect.php" method="post">
  <input type="hidden" name="act" value="run">

    <label id="Name"> Name:</label><br/>
    <input type="text" name="Name"><br/>

    <label id="Date"> Date:</label><br/>
    <input type="text" name="Date"><br/>

    <label id="Start"> Start Time:</label><br/>
    <input type="text" name="Start"><br/>

    <label id="End"> End Time:</label><br/>
    <input type="text" name="End"><br/>


  <input type="submit" value="insert">
</form>

<form action="select.php" method="get">
  <input type="hidden" name="act" value="run">
  <input type="submit" value="select">
</form>

很抱歉,如果这个问题困扰着你有经验的程序员,我一直试图解决这个问题

0 个答案:

没有答案