0

i have being tried to do solve a problem with a undefined id but i can't. It says me that i have undefined id but if i don´t use "isset" the program runs really nice but i need the file outputs the information instead of the:

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.

The file to load information is this:

<?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>"; 
}
?> 

And the html code is like this:

<?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>

If anyone knows what is wrong and can help me i will appreciate.

Best regards.

Harish Singh
  • 3,359
  • 5
  • 24
  • 39
  • possible duplicate of [PHP: "Notice: Undefined variable" and "Notice: Undefined index"](http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index) – Álvaro González Nov 26 '13 at 10:28
  • are you getting proper value while echoing $a?? – Sanal K Nov 26 '13 at 10:33

2 Answers2

0

Always make use of isset construct while assigning data

if(isset($_GET['id']))
{
$a = $_GET['id'];
}
else
{
echo "No ID Found";
}
Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126
0

You have to use a form and use hidden field to pass value

mks
  • 52
  • 6