列数与第1行的值计数不匹配,并将值插入2个表中

问题描述 投票:0回答:1
// 1. Create a database connection
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "root";
$dbname = "Group_Project_DMS";
$connection = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
// Test if connection succeeded
if(mysqli_connect_errno()) {
    die("Database connection failed: " .
        mysqli_connect_error() .
        " (" . mysqli_connect_errno() . ")"
    );
}
?>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Donor Registration</title>
</head>

<body>
<?php

$the_stid = $_POST['stid'];
$the_date = $_POST['date'];
$the_appt = $_POST['appt'];
$the_venue = $_POST['venue'];
$the_survey1 = $_POST['survey1'];
$the_survey2 = $_POST['survey2'];
$the_hkid= $_POST['hkid'];
$the_blood_type = $_POST['blood_type'];
$the_hemoglobin = $_POST['hemoglobin'];
$the_volume= $_POST['volume'];
$the_blood_pressure = $_POST['blood_pressure'];
$the_plasma = $_POST['plasma'];





$query="INSERT INTO `Donation_Record` (`staff_id`, `date`, `time`, `venue`,`donated_before`, `medical_history`, `hkid`, `blood_type`, `hemoglobin`, `volume`, `blood_pressure`, `plasma`) VALUES ('$the_stid', '$the_date', '$the_appt', '$the_venue', '$the_survey1', '$the_survey2','$the_hkid', '$the_blood_type', '$the_hemoglobin', '$the_volume','$the_blood_pressure','$the_plasma');";


    $result = mysqli_query($connection, $query);


    $the_hkid= $_POST['hkid'];
    $the_blood_type = $_POST['blood_type'];
    $the_venue = $_POST['venue'];
    $the_volume= $_POST['volume'];
    $the_plasma = $_POST['plasma'];
    $the_hemoglobin = $_POST['hemoglobin'];
    $the_expiry_date = $_POST['expiry_date'];


    $query="INSERT INTO `Blood_inventory` (`hkid`, `blood_type`,`venue`, `volume`, `plasma`, `hemoglobin`, `expiry_date`) VALUES ('$the_hkid','$the_blood_type','$the_venue','$the_plasma', '$the_hemoglobin','$the_expiry_date');";

    $date = new DateTime('+5 day');

    $result = mysqli_query($connection, $query);
if ($result)
    echo "New Record inserted into donor.<br>";
else
{
    echo "Insertion failed.<br>";
    echo "Error: " . mysqli_error($connection). "<br>";
}


mysqli_close($connection);
?>
<br><a href="register.php">Donor Registration Form</a><br>
<a href="index.php">Main page</a>
</body>
</html>
----------------------------------------

我有两个表Donation_Record和Blood_inventory。我想将Staff_id,日期,时间,地点,donated_before,病史,血型,血红蛋白,体积,血浆插入Donation_Record并将hkid,血液,地点,体积,血浆,血红蛋白和有效期从单一形式插入Blood_inventory。我在两个表中都有pack_id值,它是Donation_Record中的自动增量,并且我希望它与插入记录时出现在Blood_inventory中的相同pack_id值相同。]

// 1.创建数据库连接$ dbhost =“ localhost”; $ dbuser =“ root”; $ dbpass =“ root”; $ dbname =“ Group_Project_DMS”; $ connection = mysqli_connect($ dbhost,$ dbuser,$ dbpass,$ dbname); //测试...

php mysql
1个回答
0
投票

很简单,您错过了一个字段:

© www.soinside.com 2019 - 2024. All rights reserved.