条件bind_result与php

时间:2015-08-23 15:14:01

标签: php mysql prepared-statement

我无法将结果绑定到php变量&price但是使用不同的条件语句。它会出现以下错误。 Fatal error: Call to a member function bind_param() on a non-object 我是否需要更改bind_param()的第一个参数。 如果任何人可以帮助这个。我是新来的PHP。提前致谢。 :)

 session_start();
 include_once("config.php");

 //add product to session or create new one
if(isset($_POST["type"]) && $_POST["type"]=='add' && $_POST["product_qty"]>0)
 {
   foreach($_POST as $key => $value){ //add all post vars to new_product array
    $new_product[$key] = filter_var($value, FILTER_SANITIZE_STRING);
}

unset($new_product['type']);
unset($new_product['return_url']);

$product_size=addslashes( $_POST['product_size']);

$p_id=$_POST['p_id'];

//remove unecessary vars


//we need to get product name and price from database.
$statement = $mysqli->prepare("SELECT name FROM product WHERE p_id=? LIMIT 1");
$statement->bind_param('s', $new_product['p_id']);
$statement->execute();
$statement->bind_result($product_name);
if($product_size =='X')
{
    $statement = $mysqli->prepare("SELECT XL_price FROM product WHERE p_id=? LIMIT 1");
    $statement->bind_param('s', $new_product['p_id']);
    $statement->execute();
    $statement->bind_result($price);

}

else if($product_size=='L')
{
    $statement = $mysqli->prepare("SELECT L_price FROM product WHERE p_id=? LIMIT 1");
    $statement->bind_param('s', $new_product['p_id']);
    $statement->execute();
    $statement->bind_result($price);
}
else if($product_size=='S')
{
    $statement = $mysqli->prepare("SELECT S_price FROM product WHERE p_id=? LIMIT 1");
    $statement->bind_param('s', $new_product['p_id']);
    $statement->execute();
    $statement->bind_result($price);

}
else  if($product_size=='P')
{
    $statement = $mysqli->prepare("SELECT pan_price FROM product WHERE p_id=? LIMIT 1");
    $statement->bind_param('s', $new_product['p_id']);
    $statement->execute();
    $statement->bind_result($price);

}
else{
$price=0;
 }

while($statement->fetch()){
    $new_product["product_price"] = $price;

  }

0 个答案:

没有答案