Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP连接到MySQL表时出现问题_Php_Mysql_Forms_Mysqli - Fatal编程技术网

PHP连接到MySQL表时出现问题

PHP连接到MySQL表时出现问题,php,mysql,forms,mysqli,Php,Mysql,Forms,Mysqli,我的问题是: 1在后端,我有MySQL数据库。它包含7个表。 在前端我有一个HTML表单。 3用户输入的数据必须填充这7个表。 4我使用PHP并使用mysqli将表单链接到数据库 出于某种原因,表单只填充了第一个表,而其他6个表没有收到任何数据。你知道如何将表单一次连接到所有表吗?我不想要一个sql表,因为HTML表单有300多个输入字段。 谢谢你 编辑 这是密码 <?php $host="localhost"; $user="root"; $pass=""; $db="ao db";

我的问题是:

1在后端,我有MySQL数据库。它包含7个表。 在前端我有一个HTML表单。 3用户输入的数据必须填充这7个表。 4我使用PHP并使用mysqli将表单链接到数据库

出于某种原因,表单只填充了第一个表,而其他6个表没有收到任何数据。你知道如何将表单一次连接到所有表吗?我不想要一个sql表,因为HTML表单有300多个输入字段。 谢谢你

编辑

这是密码

<?php
$host="localhost";
$user="root";
$pass="";
$db="ao db";

$conn = new mysqli ($host, $user, $pass, $db);

if ($conn->connect_error) { 
die("Connection failed: " . $conn->connect_error);
}

$firstname = $_POST["first_name"];
$lastname = $_POST["name"]; 
$female = $_POST["female"];

$stmt = $conn->prepare("INSERT INTO table_demo (Vorname, Nachname, female) VALUES (?, ?, ?)");
$stmt->bind_param("ssi", $firstname, $lastname, $female);

$stmt->execute();
$stmt->close();
echo "New records created in Demo";
$conn->close();

$link = new mysqli ($host, $user, $pass, $db);

if ($link->connect_error) { 
die("Connection failed: " . $link->connect_error);
}

$height = $_POST["height"];
$weight = $_POST["weight"];

$stmt=$link->prepare("INSERT INTO table_pre (height, weight) VALUE (?, ?)");
$stmt->bind_param("ii", $height, $weight);

$stmt->execute();

$stmt->close();
echo "New records created in Pre";
$link->close();
>

对于代码,首先必须创建db连接对象。 `

用于插入表格中。借助此帮助,您可以在所有七个表中插入详细信息

$sql=插入MyGuests的firstname、lastname、emailVALUES'John'、'Doe'、'john@example.com';

使用此函数从表中获取详细信息。借助于此,您可以从所有七个表中进行选择

$sql=从MyGuests中选择id、firstname、lastname; $result=$conn->query$sql


我知道了!有两个问题:

问题一:表创建不正确,外键连接错误。我在通过phpmyadmin菜单创建带有外键的表时遇到问题。也许最好使用SQL数据库和表创建语法:

CREATE DATABASE IF NOT EXISTS database_name;

USE database_name;

CREATE TABLE table_1
(
    table_1_id int not null auto_increment primary key,
    variable_1 varchar(255) not null,
    variable_2 int(11),
    ...
    variable_to_be_used_as_foreign_key text,
    variable_n text,
) ENGINE=InnoDB;

CREATE TABLE table_2
(
    table_2_id int not null auto_increment primary key,
    variable_1 varchar(255) not null,
    variable_2 int(11),
    ...
    variable_n text,
    variable_to_be_used_as_foreign_key text,

    FOREIGN KEY fk_table_2(variable_to_be_used_as_foreign_key)
         REFERENCES table_1(variable_to_be_used_as_foreign_key)
              ON UPDATE CASCADE
              ON DELETE RESTRICT
) ENGINE=InnoDB;
请注意:必须在两个表中都添加外键变量。我知道这很明显,但仍然存在

问题2:php代码中出现故障。我在准备好的语句中遗漏了第二个表外键列中的输入,即:

$stmt=$link->prepare("INSERT INTO table_pre (height, weight) VALUE (?, ?)");
$stmt->bind_param("ii", $height, $weight);
而不是:

$stmt=$link->prepare("INSERT INTO table_pre (height, weight, female) VALUE (?, ?, ?)");
$stmt->bind_param("iii", $height, $weight, $female);

展示你所做的。显示您的代码,以便我们可以为您提供帮助。可以使用SQL join查询,但请提供您迄今为止所做的工作,以便我们对其进行评论和帮助。代码已上载,谢谢。是否要对多个表执行多个插入?我说的对吗?@HafizK是的。我想在一个数据库的多个表中进行多个插入。我有一个表单和一个提交按钮。数据库中的表已连接。第一个table_demo包含主_键,其他6个table与一个外键相关。由于某些原因,只有主键为的表接收到数据,其他表为空。请先阅读问题!当您使用w3school参考时,请添加您的源代码!根据您的问题,您无法在表中插入详细信息。这里我给你一些关于插入和选择数据的建议。请先阅读问题。这很清楚。7是一个数字,表示我有七个表,其中六个表无法接收数据。我需要一个人口七表的解决方案。在一起没有一张表。请给我你的全部数据库和sharma的代码。bimal226@gmail.com. 我会调查此事并为您提供解决方案。
$stmt=$link->prepare("INSERT INTO table_pre (height, weight, female) VALUE (?, ?, ?)");
$stmt->bind_param("iii", $height, $weight, $female);