我的demo.php代码如下。我得到的错误是您的SQL语法中有错误;检查与MySQL服务器版本对应的手册,以便在''FullName','Email','Postcode','DateofBirth','Gender'附近使用正确的语法)VALUES('David Beckham','在第1行< / em>的
<?php
define('DB_NAME', 'testdb');
define('DB_USER', 'root');
define('DB_PASSWORD', '');
define('DB_HOST', 'localhost');
//logon
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link){
die('Could not connect: '. msql_error());
}
$db_selected = mysql_select_db(DB_NAME, $link);
if(!$db_selected){
die('Cant use' . DB_NAME . ':' . mysql_error());
}
$value = $_POST['FullName'];
$value2 = $_POST['Email'];
$value3 = $_POST['Postcode'];
$value4 = $_POST['DateofBirth'];
$value5 = $_POST['Gender'];
//insert into table.
$sql = "INSERT INTO demo ('FullName', 'Email', 'Postcode', 'DateofBirth', 'Gender') VALUES ('$value', '$value2', '$value3', '$value4', '$value5')";
if(mysql_query($sql)){
echo "Thank you for signing up";
}else{
die('Error:'. mysql_error());
}
mysql_close();
?>
答案 0 :(得分:4)
您需要将列名包装在backtricks(`)
中$sql = "INSERT INTO demo (`FullName`, `Email`, `Postcode`, `DateofBirth`, `Gender`) VALUES('$value', '$value2', '$value3', '$value4', '$value5')";
答案 1 :(得分:0)
问题在于您用于列名的引号。您应该使用严重重音标点符号(通常在 1 键的左侧,并在代字号中找到)
INSERT INTO demo (`FullName`, `Email`, `Postcode`, `DateofBirth`, `Gender`) VALUES ('$value1', '$value2', '$value3', '$value4', '$value5');