Query INNER JOIN apply bind parameter

Asked

Viewed 87 times

0

Original query:

SELECT quantity.order_id, quantity.ISBN, quantity.quantity,orders.customer_id, orders.created, orders.status FROM orders INNER JOIN quantity ON orders.order_id=quantity.order_id"

Query with bind Parameter:

$stmt = $conn->prepare ("SELECT quantity.order_id, quantity.ISBN, quantity.quantity,orders.customer_id, orders.created, orders.status FROM orders INNER JOIN quantity ON orders.order_id=?");
$stmt->bind_param("i",$quantity.order_id);
$quantity.order_id = $_POST['quantity.order_id'];//linha 6
$stmt->execute();
$stmt->get_result();

With the bind Parameter I am having the following error:Parse error: syntax error, Unexpected '=' on line 6

  • The name of the parameter you receive in the POST seems to be wrong!

  • Variable name is already wrong. Not allowed to have ..

  • how do you suggest I do it? sorry I’m new to PHP

  • Use underline instead of point to name variables!

  • Quantity.order_id is to fetch information the data base is to fetch the order id of the Quantity table!!

  • see the answer I put, you do not put a column of the table Quantity in the JOIN ON clause, see if the way I put works for you

Show 1 more comment

2 answers

1

Try:

$stmt = $conn->prepare ("SELECT quantity.order_id, quantity.ISBN, quantity.quantity,orders.customer_id, orders.created, orders.status FROM orders INNER JOIN quantity ON orders.order_id=quantity.order_id and quantity.order_id=?");
$stmt->bind_param("i",$quantity.order_id);
$quantity.order_id = $_POST['quantity.order_id'];//linha 6
$stmt->execute();
$stmt->get_result();

OR:

$stmt = $conn->prepare ("SELECT quantity.order_id, quantity.ISBN, quantity.quantity,orders.customer_id, orders.created, orders.status FROM orders INNER JOIN quantity ON orders.order_id=quantity.order_id Where quantity.order_id=?");
$stmt->bind_param("i",$quantity.order_id);
$quantity.order_id = $_POST['quantity.order_id'];//linha 6
$stmt->execute();
$stmt->get_result();

0

$stmt = $conn->prepare("SELECT quantity.order_id, quantity.ISBN, quantity.quantity,orders.customer_id, orders.created, orders.status FROM orders INNER JOIN quantity ON (orders.order_id=quantity.order_id) WHERE quantity.order_id=:id");

$stmt->bind_param(":id",$_POST['quantity.order_id'],PDO::PARAM_INT);

if($stmt->execute())
{
    if($stmt->rowCount() < 1)
        echo "Nenhum resultado encontado.";
    else
        $stmt->fetchAll(PDO::FETCH_NUM);
}
else
    echo "erro";

This variable $_POST['Quantity.order_id'] is correct? It comes from some form?

Try changing to a name without punctuation, for example:

$_POST['quantity_order_id'].

in HTML should be:

<input name="quantity_order_id" />

Browser other questions tagged

You are not signed in. Login or sign up in order to post.