首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >$id = $_GET['id']

$id = $_GET['id']
EN

Stack Overflow用户
提问于 2015-04-28 13:22:06
回答 1查看 3.5K关注 0票数 0

我一直收到通知说Undefined index: id.而且,代码没有做它想要做的事情。它应该从ItemID = ID所在的数据库中获取数据。但这一页只是空白。

帮帮忙,我能做什么?

代码语言:javascript
复制
<!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>
EN

回答 1

Stack Overflow用户

发布于 2015-04-28 13:31:26

您忘了添加PHP标记的开始。在此包括:

代码语言:javascript
复制
<?php //add this tag
session_start();
include(connect.php);

要显示错误,请在顶部的文件中添加ini_set:

代码语言:javascript
复制
<?php ini_set('display_errors', true); ?>

希望这能解决这个问题。

更新:

如果不是从id参数传递$_GET,那么将$_GET替换为$_REQUEST。您也可以尝试这种方法。$_REQUEST可以同时获得get和POST值。

脚注:

您可能在页眉之前输出(参见下面的链接),但是隐藏PHP在后台向您抛出的错误。

使用error reporting会告诉你。

如果是这样的话,那么您需要将session_start();放在代码的顶部,然后是您的代码的其余部分。

即:

代码语言:javascript
复制
<?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 code
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29920794

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档