查询为空错误,我可以';我不知道为什么


query was empty error and I can't work out why

我开始构建一个非常简单的产品展示系统,主要是为了构建我自己的技能,也可以在我的网站上使用。

List.php

<html>
<head>
<title>Retrieve data from the database</title>
<?php
$username='';
$password='';
$database='';
?>
</head>
<body>
<ul>
<?php
// Connect to database server
mysql_connect(localhost,$username,$password); 

// Select database
@mysql_select_db($database) or die( 'Unable to select database');  
// SQL query
$sql = "SELECT * FROM products WHERE category = 30";
// Execute the query (the recordset $rs contains the result)
$result = mysql_query($sql);
// Loop the recordset $rs
while($row = mysql_fetch_array($result)) {
   // Name of the person
  $strName = $row['make'];  
       // Create a link to person.php with the id-value in the URL
   $strLink = "<a href = 'product.php?id = " . $row['ID'] . "'>" . $strName . "</a>";
    // List link
   echo "<li>" . $strLink . "</li>";
  }
// Close the database connection
mysql_close();
?>
</ul>
</body>
</html>

产品.php

<html>
<head>
<title>Retrieve data from database</title>
</head>
<body>
<?php
$username="";
$password="";
$database="";
// Connect to database server
mysql_connect(localhost,$username,$password); 

// Select database
@mysql_select_db($database) or die( "Unable to select database");
// Get data from the database depending on the value of the id in the URL
$sql = mysql_query('SELECT * FROM products WHERE ID=' . $_GET["ID"]);
$result = mysql_query($sql); 
if(!$result)
    die(mysql_error());
// Loop the recordset 
while($row = mysql_fetch_array($result)) {
    // Write the data of the product
    echo $row['category'];
    echo "<p>";
    echo $row["make"];
    echo "<p>";
    echo $row["description"];
    echo "<p>";
    echo $row["picture"];
}
// Close the database connection
mysql_close();
?>
<p><a href="list.php">Return to the list</a></p>
</body>
</html>

可以看到这里的混乱不堪

如果有人能帮我做这件事,我将不胜感激!

尝试这种方法,但不能完全确定这个顽固的问题。您可以尝试使用array_change_key_case()$_GET数组的所有键的大小写更改为小写

$get = array_change_key_case($_GET);
$id = $get['id'];
$sql = mysql_query('SELECT * FROM products WHERE ID=' . $id);

注意:首先确定SELECT * FROM products WHERE ID=your_row_id是否返回结果?

我发现页面"list.php"生成的链接格式不正确。

更改此:

$strLink = "<a href = 'product.php?id = " . $row['ID'] . "'>" . $strName . "</a>";

$strLink = "<a href = 'product.php?id=".$row['ID']."'>" . $strName . "</a>";

它现在正按照它应该的方式工作!