Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/243.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 查询为空错误,我无法找出原因_Php - Fatal编程技术网

Php 查询为空错误,我无法找出原因

Php 查询为空错误,我无法找出原因,php,Php,我开始建立一个非常简单的产品展示系统,主要是为了培养我自己的技能,也为了在我的网站上工作 List.php <html> <head> <title>Retrieve data from the database</title> <?php $username=''; $password=''; $database=''; ?> </head> <body> <ul> <?php // Co

我开始建立一个非常简单的产品展示系统,主要是为了培养我自己的技能,也为了在我的网站上工作

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>
Product.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\u change\u key\u大小写将$\u GET数组的所有键的大小写更改为小写


注意:首先确保从ID=your_row_ID的产品中选择*是否返回结果?

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

更改为:

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


现在它完全按照它应该的方式工作

强制性的,并且您有一个SQL注入漏洞注释。您应该在mysql\u connect语句中引用“localhost”。现在,我已经更改了一些代码,现在如果我指定了我想要的ID,它将按照我的要求显示产品。但我补充的第二点$_获取[ID];我收到以下错误。。。。警告:mysql\u查询期望参数1是字符串,在第21行的/home/haslemer/public\u html/test/product.php中给出的资源我也注意到,在URL中,而不是?id=I get?id%中,这会影响什么吗?谢谢你的帮助。编辑:第21行是空的吗?
$strLink = "<a href = 'product.php?id = " . $row['ID'] . "'>" . $strName . "</a>";
$strLink = "<a href = 'product.php?id=".$row['ID']."'>" . $strName . "</a>";