简体   繁体   English

在单一表格中插入php中的多个表格

[英]insert into multiple tables in php within a single form

I have created a form and here is the insert command for inserting values into the database. 我已经创建了一个表单,这是用于将值插入数据库的插入命令。 The first query $query1 is executed but the second one is not. 第一个查询$ query1被执行,但是第二个查询没有被执行。 So I am getting the "seller INSERT failed" 所以我得到“卖方插入失败”

<?php
$book_author = mysqli_real_escape_string($con, $_POST['b_author']);;
$book_branch = mysqli_real_escape_string($con, $_POST['b_branch']);
$book_edit = mysqli_real_escape_string($con, $_POST['b_edit']);
$book_name = mysqli_real_escape_string($con, $_POST['b_name']);
$book_price = mysqli_real_escape_string($con, $_POST['b_price']);
$book_pub = mysqli_real_escape_string($con, $_POST['b_pub']);
$book_qty = mysqli_real_escape_string($con, $_POST['b_qty']);
$name = mysqli_real_escape_string($con, $_POST['s_name']);
$email = mysqli_real_escape_string($con, $_POST['email']);
$phNo = mysqli_real_escape_string($con, $_POST['phNo']);
$clg = mysqli_real_escape_string($con, $_POST['college']);

$query1 = "INSERT INTO `book_info`(book_author,book_branch,book_edit,book_name,book_price,book_pub,book_qty) VALUES".
"('$book_author','$book_branch','$book_edit','$book_name','$book_price','$book_pub','$book_qty')";

$query2 = "INSERT INTO `seller_info`(seller_name,seller_email,seller_phno,seller_college) VALUES".
"('$name','$email','$phNo','$clg')";
$result1 = mysqli_query($con, $query1);
$result2 = mysqli_query($con, $query2);
if (!$result1)
   echo "Book INSERT failed: $query1";
if (!$result2)
   echo "seller INSERT failed $query2 <br />".
mysql_error() . "<br /><br />";

?>

Put this after the failing query, or in place of echo "seller INSERT failed $query2 <br />". 将其放在失败的查询之后,或代替echo "seller INSERT failed $query2 <br />".

echo mysqli_error($con);

This will tell you exactly what the error was. 这将准确告诉您错误所在。 (It might be seller_phno not being spelled correctly.) (可能是seller_phno拼写不正确。)

More information can be found here 更多信息可以在这里找到

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM