Query INNER JOIN apply bind parameter

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 getting the following error: Parse error: syntax error, unexpected '=' on line 6

    
asked by anonymous 25.05.2017 / 19:32

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();

OU:

$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();
    
25.05.2017 / 20:17
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";

Is this variable $ _ POST ['quantity.order_id'] correct? Does it come in any form?

Try switching to a name with no punctuation, for example:

$ _ POST ['quantity_order_id'].

HTML should stay:

<input name="quantity_order_id" />

    
25.05.2017 / 19:45