0

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

?>
2
  • Only a guess, what is seller_phno? Do you mean seller_phone? Commented Sep 30, 2014 at 15:06
  • 1
    When using mysqli you should be using parameterized queries and bind_param to add user data to your query. DO NOT use string interpolation to accomplish this because you will create severe SQL injection bugs. Placeholders also avoid the giant mess of "escape string" calls you have there. Commented Sep 30, 2014 at 15:08

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.