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

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

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?