gpt4 book ai didi

PHP SQL 错误资源#6

转载 作者:行者123 更新时间:2023-11-29 06:15:30 25 4
gpt4 key购买 nike

这是我的代码:

//Connect to config file
include(dirname(__FILE__)."/../config.php");
//Connect to the database
$db = mysql_connect("$dbHost", "$dbUser", "$dbPass") or die ("Error connecting to database.");
mysql_select_db("$dbDatabase", $db) or die ("Couldn't select the database.");

//Get Total Products
$result = mysql_query("SELECT * FROM $dbProductsTable WHERE sub_cat = '$subcat'");
$TotalProducts = mysql_num_rows($result);

//Create Pages
if (TotalProducts <= 12){
$pages = '';
}else{
$pages = " <ul id=\"pagination\" class=\"group\">
<li><a class=\"current\" href=\"#\">1</a></li>
<li><a href=\"#\">2</a></li>
<li><a href=\"#\">3</a></li>
<li><a href=\"#\">4</a></li>
</ul>";
}




//Get from sql info we need
$sql = mysql_query("SELECT * FROM $dbProductsTable WHERE sub_cat = '$subcat' LIMIT 0 , 12");
$data = mysql_query($sql) or die(mysql_error());

//Make first letter UpperCase
$subcatname = ucfirst($subcat);
//Get Basket Count
$basketcount = count($_COOKIE['products']);

//Get All Products
while($row = mysql_fetch_array($data))
{
//Get Product Path
$productPath = $Domain.'/'.strtolower($row['category']).'/'.str_replace(" ","",$row['product_name']).'_'.$row['product_id'];

//Build Products List
$products = $products." <li class=\"all-products-list-item\">
<a href=\"$productPath\" title=\"{$row['product_name']}\"><img src=\"$ProductImageFolder{$row['thumb_image']}\" alt=\"{$row['product_name']}\" border=\"0\" height=\"245\" width=\"180\"/></a>
<h3><a href=\"$productPath\">{$row['product_name']}</a></h3>
<p>£{$row['price']}</p>
</li>\n";
}

这是错误:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #6' at line 1

我尝试通过 phpmyadmin 运行它,并且 sql 工作完美,我找不到问题是什么?

谢谢

最佳答案

这里是错误:

//Get from sql info we need
$sql = mysql_query("SELECT * FROM $dbProductsTable WHERE sub_cat = '$subcat' LIMIT 0 , 12");
$data = mysql_query($sql) or die(mysql_error());

更改为

//Get from sql info we need
$sql = "SELECT * FROM $dbProductsTable WHERE sub_cat = '$subcat' LIMIT 0 , 12";
$data = mysql_query($sql) or die(mysql_error());

您正在使用$sql = mysql_query(...)运行查询,并将资源分配给变量$sql。之后,您尝试使用变量 $sql 作为参数来运行查询。此时,$sql 将包含资源,而不是查询。

关于PHP SQL 错误资源#6,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6844276/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com