无法从php中获取sqli的数据

时间:2015-01-20 05:48:23

标签: php mysqli

我正在尝试从数据库显示这些值,但它显示了一个错误,如果条件plz告诉我我在哪里做错了?

$sql1 = "SELECT * FROM Batch b, Vendor v, Product p WHERE 'v.id' = 'b.id', 'p.id' = 'b.id' and 'b.batch_no' = $batchno";

$retval = mysqli_query($conn,$sql1);

if(!$retval)
{
    die('Could not get data:' . $conn->connect_error);
}

else
{
    echo "<input type = 'submit' value = 'Print Bill'><br>";
    echo "<h3>Bill</h3>";
    while($row = mysqli_fetch_array($retval,MYSQL_ASSOC))
    {
        echo "Vendor Name :{$row['name']} <br> " .
         "Batch No:{$row['batchno']} <br> " .
         "Product Size:{$row['product_size']} <br> " .
         "Product Price Per Unit:{$row['product_price']} <br> " .
         "Product Quantity:{$row['quantity']} <br> " .
         "------------------------------<br>";
    }
}

3 个答案:

答案 0 :(得分:0)

如果您的数据库已连接,请先检查您的连接

并尝试

"SELECT * FROM batch b Inner join Vendor v on v.id=b.id inner join Product p on p.id=b.id where b.batch_no=".$batchno

答案 1 :(得分:0)

您必须加入表格,然后使用“on”告诉它如何链接表格。

http://dev.mysql.com/doc/refman/5.0/en/join.html

也不确定$ batchno是什么,但可能会打开你的查询注射。 http://en.wikipedia.org/wiki/SQL_injection

答案 2 :(得分:0)

在你的SQL查询中有而不是代替,

$sql1 = "SELECT * FROM Batch b, Vendor v, Product p WHERE 'v.id' = 'b.id' and 'p.id' = 'b.id' and 'b.batch_no' = $batchno";