$ _GET不为null并返回未定义的id

时间:2013-11-26 10:25:39

标签: php html undefined-index

我试图解决一个未定义id的问题,但我不能。它告诉我,我有未定义的ID,但如果我不使用“isset”程序运行非常好,但我需要文件输出信息而不是:

Notice: Undefined index: id in C:\xampp\htdocs\treeview_v2\load_url_db.php on line 17

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\treeview_v2\load_url_db.php on line 23

Notice: Undefined variable: url in C:\xampp\htdocs\treeview_v2\load_url_db.php on line 27.

要加载信息的文件是:

<?php

include_once 'acess_db.php';

//echo $_GET['id'];
////
//
//if(isset($_GET['id']))
//{
//    read_url();
//}
//else
//{
//    echo 'erro...';
//}

$a = $_GET['id'];
echo $a;
read_url($a);
function read_url($id)
{
    $rs = mysql_query("select url from dados3 where id=$id");
    while($row = mysql_fetch_array($rs))
    {
         $url = $row["url"];
    }
    echo "<iframe src=\"{$url}\" style=\"height=\"75%\"  width=\"100%\"></iframe>"; 
}
?> 

html代码是这样的:

<?php include_once 'load_url_db.php';?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="keywords" content="jquery,ui,easy,easyui,web">
    <meta name="description" content="easyui help you build your web page easily!">
    <title>Async Tree - jQuery EasyUI Demo</title>
    <link rel="stylesheet" type="text/css" href="http://www.jeasyui.com/easyui/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="http://www.jeasyui.com/easyui/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="http://www.jeasyui.com/easyui/demo/demo.css">
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.1.min.js"></script>
    <script type="text/javascript" src="http://www.jeasyui.com/easyui/jquery.easyui.min.js"></script>
</head>
<body>
    <div style="width: 300px; float: left;">      
        <ul id="tt" class="easyui-tree" url="get_tree_data_id.php" data-options="animate:true" >
        </ul>
    </div>  
<!--    A IFRAME CARREGA A SRC ATRAVES DO PHP-->
<div>
    <iframe id="a" name="ifrm1" style="float: right; width: 80%; height: 100%; visibility: hidden;" src='load_url_db.php'>     
    </iframe>
    <button class="button" onClick="getIframeContent(a);"><span class="icon">Open</span></button>
</div>

<script language="Javascript" type="text/javascript">
//TORNA A IFRAME VISIVEL      
$('#tt').tree({
    onClick: function(){
        console.log("Entrou na funçao..");
        $("#a").css("visibility", "visible");
        var node = $('#tt').tree('getSelected');      
        console.log("Selecionou o no..");
        $("#a").attr('src', "load_url_db.php?id=" + node.id);     
        console.log("ID do no selecionado:  " + node.id);
    }
});
</script>  

</body>
</html>

如果有人知道什么是错的,可以帮助我,我会很感激。

最好的问候。

2 个答案:

答案 0 :(得分:0)

在分配数据时始终使用 isset 构造

if(isset($_GET['id']))
{
$a = $_GET['id'];
}
else
{
echo "No ID Found";
}

答案 1 :(得分:0)

您必须使用表单并使用隐藏字段传递值