错误INSERT INTO记录错误的我的SQL语法

时间:2018-03-24 03:05:15

标签: php mysql

我正在尝试使用Web钩子将python中的值插入到mysql数据库中。但是,当我运行它时,我收到错误:

  

"错误:INSERT INTO记录(timestamp,tensor,float1,int1)VALUES(' 1521860398',' 1',' 2', ' 3')   您的SQL语法有错误;检查与您的MySQL服务器版本相对应的手册,以便在#int; int1)VALUES附近使用正确的语法(' 1521860398',' 1',' 2&#39 ;,' 3')'在第6行"

我的php代码如下所示:

<?php
if($_GET["token"]=="oSImm4M9ke52QhovmmqeFgpDS0dKTirwV5") {

#If Statement to get a token from TFLearn
#IF Statement to make sure all the data is set
$servername = "localhost";
$username = "Chip15334";
$password = "Chip1214";
$dbname = "code_output_metrics";

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

#Put in a PHP database call

#Use a PHP "GET" from the data being passed from the dataset and then     add it to a database row]

$timestamp = time();
$tensor = $_GET['tensor'];
$Float1 = $_GET['Float'];
$int1 = $_GET['int'];

$sql = "INSERT INTO records
(
timestamp,
tensor,
float1,
int1
)
VALUES (
'$timestamp',
'$tensor',
'$Float1',
'$int1'
)";

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

$conn->close();

} else {
    echo "wrong token";
}
?>

1 个答案:

答案 0 :(得分:2)

以下是mysql中的保留关键字。您不能拥有名为int1的列。

Reserved word => Synonym
INT1          => TINYINT 
INT2          => SMALLINT 
INT3          => MEDIUMIN 
INT4          => INT 
INT8          => BIGINT 

https://forums.mysql.com/read.php?152,569810,572087#msg-572087