我必须遵循错误 "错误:您的SQL语法出错;查看与您的MariaDB服务器版本对应的手册,以获得在''附近使用的正确语法。在第2行"
这是我将表单数据插入表格的脚本。
<?php
include("config.php");
$dbcon = new mysqli($host, $username, $pass, $database);
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$inputCode=mysqli_real_escape_string($dbcon, $_POST['inputCode']);
$inputType=mysqli_real_escape_string($dbcon, $_POST['inputType']);
$inputRoom=mysqli_real_escape_string($dbcon, $_POST['inputRoom']);
$inputStartTime=mysqli_real_escape_string($dbcon, $_POST['inputStartTime']);
$inputEndTime=mysqli_real_escape_string($dbcon, $_POST['inputEndTime']);
$inputDow=mysqli_real_escape_string($dbcon, $_POST['inputDow']);
$inputStartDate=mysqli_real_escape_string($dbcon, $_POST['inputStartDate']);
$inputEndDate=mysqli_real_escape_string($dbcon, $_POST['inputEndDate']);
$sql="INSERT INTO class(ModuleCode,Type,Room,StartTime,EndTime,DayOfWeek,StartDate,EndDate)VALUES
('$inputCode','$inputType','$inputRoom','$inputStartTime','$inputEndTime','$inputDow','$inputStartDate','$inputEndDate'";
if (!mysqli_query($dbcon,$sql)) {
die('Error: ' . mysqli_error($dbcon));
}
echo "1 record added";
mysqli_close($con);
?>
答案 0 :(得分:1)
你错过了a)改变
$sql="INSERT INTO class(ModuleCode,Type,Room,StartTime,EndTime,DayOfWeek,StartDate,EndDate)VALUES
('$inputCode','$inputType','$inputRoom','$inputStartTime','$inputEndTime','$inputDow','$inputStartDate','$inputEndDate'";
到
$sql="INSERT INTO class(ModuleCode,Type,Room,StartTime,EndTime,DayOfWeek,StartDate,EndDate)VALUES
('$inputCode','$inputType','$inputRoom','$inputStartTime','$inputEndTime','$inputDow','$inputStartDate','$inputEndDate')";