douxun7992 2014-09-30 15:01
浏览 51
已采纳

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

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. 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 />";

?>
  • 写回答

1条回答 默认 最新

  • dongzhangnong2063 2014-09-30 15:05
    关注

    Put this after the failing query, or in place of 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.)

    More information can be found here

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch