我一直收到通知说Undefined index: id.而且,代码没有做它想要做的事情。它应该从ItemID = ID所在的数据库中获取数据。但这一页只是空白。
帮帮忙,我能做什么?
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<link rel="stylesheet" href="my.css">
<title>Search result</title></head>
<body >
<div id = "header"> <h2> Descriptions and Images</h2></div>
<div id = "main">
session_start();
include(connect.php);
$id = isset($_GET['id']) ? $_GET['id'] : '';
//$id= $_GET['id'];
//$id = '';
//f( !isset( $_GET['id'])) {
// $id = $_GET['id']; }
//if ($id == ""){
// echo"eree";
//}
echo $id;
$query = mysql_query('SELECT * FROM PHP_Item WHERE ItemID = "$id"');
//$row = mysql_fetch_array($query);
while ($row = mysql_fetch_array($query)){
$Name = $row['Name'];
$Price = $row['Price'];
$Description = $row['Description'];
$Image = $row['Image'];
echo "<br /><br/>";
echo "Name: " . $Name;
echo "<br/>";
echo "Price: " . $Price;
echo "<br/>";
echo "Description: ".$Description;
echo "<br/>";
echo "<img src = '".$Image."' alt = '".$Image."'></img>";
echo"<br/><br/>";
}
?>
</div>
<div id = "footer">
<a href = "logout.php">Logout</a></div>
</html>发布于 2015-04-28 13:31:26
您忘了添加PHP标记的开始。在此包括:
<?php //add this tag
session_start();
include(connect.php);要显示错误,请在顶部的文件中添加ini_set:
<?php ini_set('display_errors', true); ?>希望这能解决这个问题。
更新:
如果不是从id参数传递$_GET,那么将$_GET替换为$_REQUEST。您也可以尝试这种方法。$_REQUEST可以同时获得get和POST值。
脚注:
您可能在页眉之前输出(参见下面的链接),但是隐藏PHP在后台向您抛出的错误。
使用error reporting会告诉你。
如果是这样的话,那么您需要将session_start();放在代码的顶部,然后是您的代码的其余部分。
即:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
session_start();
?>
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<link rel="stylesheet" href="my.css">
<title>Search result</title></head>
<body >
<div id = "header"> <h2> Descriptions and Images</h2></div>
<div id = "main">
<?php
include(connect.php);
// rest of your codehttps://stackoverflow.com/questions/29920794
复制相似问题