无法插入 MYSQL table

Failed to insert into MYSQL table

是的,我只是在构建我的项目之前做了一些测试,但我不断收到错误。我正在为数据库使用 WAMP 和 phpmyadmin。

我已成功连接到数据库,但似乎无法将数据插入 table。

最终我想插入用户从表单上传的数据,但我现在使用静态数字以使 INSERT 正常工作。

所以当用户点击提交时,我希望这个 运行;

PHP/MYSQL:

define("DB_SERVER", "localhost");
define("DB_USER", "root");
define("DB_PASS", "#########");//I have hashed out the password here
define("DB_NAME", "uploads");

// 1. Create a database connection
$connection = mysqli_connect(DB_SERVER, DB_USER, DB_PASS, DB_NAME);
// Test if connection succeeded
if(mysqli_connect_errno()) {
  die("Database connection failed: " . 
       mysqli_connect_error() . 
       " (" . mysqli_connect_errno() . ")"
  );
}


    $query =  "INSERT INTO ";
    $query .= "customers "; 
    $query .= "(`reference`, `doc1`, `doc2`, `doc3`) ";
    $query .= "VALUES ('123456', 'newimage1.jpg', 'newimage2.jpg', 'newimage3.jpg')";
    $result = mysqli_query($connection, $query);
    if ($result) {
      echo "created insert";
    } else {
      // Failure
      echo "failed to insert";
    }

好的,数据库连接正常,因为它没有抛出任何错误,但是我只得到 "failed to insert"。

有什么想法吗?如果您需要更多信息,请 post 评论

编辑:

回显我得到的 $query:

INSERT INTO customers(reference, doc1, doc2, doc3) VALUES ('123456', 'newimage1.jpg', 'newimage2.jpg' ,'newimage3.jpg')插入失败

如果我删除 customers

上的 space 也是一样的

正在工作:

varchar 11 的字段,文本太长无法插入。非常愚蠢的错误哈哈,使用 MYSQL 和 php 比较陌生。但感谢您的帮助!

根据你的问题,你 table 结构中有一个错误更改 varchar 大小(增加超过 11 )以插入数据 int table 列 doc1 doc2 doc3