如何使数据输入我的sql表?

时间:2019-07-29 01:08:34

标签: php sql

更改一件事后,提交的数据不会上传到mysql表中。

我最近在表“ gallery”中添加了一个外键,该表将用户ID连接到两个表。在执行此操作之前,数据将上传,但是在添加外键(idUsers)之后,数据将不会显示在表中。我创建了没有外键的第二个表(gallery2),它可以上传并显示得很好。

这个不在表格中显示数据

$sql = "SELECT * FROM gallery;";
                $stmt = mysqli_stmt_init($conn);
                if (!mysqli_stmt_prepare($stmt, $sql)){
                    echo "SQL statement failed3!";
                }   

$sql = "INSERT INTO gallery (titleGallery, descGallery, imgFullNameGallery, orderGallery, ) VALUES (?, ?, ?, ?);";

CREATE TABLE gallery (
  idGallery int(11) AUTO_INCREMENT PRIMARY KEY not null,
  titleGallery LONGTEXT not null,
  descGallery LONGTEXT not null,
  imgFullNameGallery LONGTEXT not null,
  orderGallery int(11) not null
   idUser int(11) not null,
  FOREIGN KEY (idUser) REFERENCES users(idUsers)
);

此作品100%

$sql = "SELECT * FROM gallery2;";
                $stmt = mysqli_stmt_init($conn);
                if (!mysqli_stmt_prepare($stmt, $sql)){
                    echo "SQL statement failed3!";
                }  


$sql = "INSERT INTO gallery2 (titleGallery, descGallery, imgFullNameGallery, orderGallery, ) VALUES (?, ?, ?, ?);";


CREATE TABLE gallery2 (
  idGallery int(11) AUTO_INCREMENT PRIMARY KEY not null,
  titleGallery LONGTEXT not null,
  descGallery LONGTEXT not null,
  imgFullNameGallery LONGTEXT not null,
  orderGallery int(11) not null
);

我希望上载的数据进入表库,但表中什么都没有显示。

0 个答案:

没有答案