chain select error undefined index

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kkshansid
    New Member
    • Oct 2008
    • 232

    chain select error undefined index

    i am trying to use chain select on a form
    i am facing two problems
    1. dept is fetching branch but branch is not fetching designations.
    2. same form is not posting all three dropdowns and therefore insert not possible as it is showing error.
      Notice: Undefined index: branch in C:\xampp\htdocs \w.php on line 35

      Notice: Undefined index: desg in C:\xampp\htdocs \w.php on line 36
      2---------------------------/-------------------------------------------/----------------





    w.php
    Code:
     <html>
    <head>
    <script>
    function showUser(str) {
        if (str == "") {
            document.getElementById("txtHint").innerHTML = "";
            return;
        } else {
            if (window.XMLHttpRequest) {
                // code for IE7+, Firefox, Chrome, Opera, Safari
                xmlhttp = new XMLHttpRequest();
            } else {
                // code for IE6, IE5
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            xmlhttp.onreadystatechange = function() {
                if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                    document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
                }
            }
            xmlhttp.open("GET","x.php?q="+str,true);
            xmlhttp.send();
        }
    }
    
    </script>
    </head>
    <body>
    <?php
    require_once('includes/load.php');
     if(isset($_POST['add_file'])){
    	// echo"kkshan";
    	 //exit;
    	 $f_dept  = strtoupper(remove_junk(real_escape($_POST['dept'])));
    	  $f_branch  = strtoupper(remove_junk(real_escape($_POST['branch'])));
    	   $f_desg  = strtoupper(remove_junk(real_escape($_POST['desg'])));
    	  echo $f_dept."---------------------------/----------------".$f_branch ."---------------------------/----------------".$f_desg;
    	  //i want to insert these in database
    	  
     }else{//echo"kkshan";
    	 //exit;
    	 
    ?>
     <form method="post" class="clearfix">
    <select name="dept" onchange="showUser(this.value)">
      <option value="">Select a dept:</option>
      <option value="1">XXX</option>
      <option value="2">YYY</option>
      <option value="3">OTHERS</option>
     
      </select>
      
      <TD><button type="submit" name="add_file" class="btn btn-info pull-right">Add file</button></TD></TR>
    </form>
    <br>
    <div id="txtHint"><b>Person info will be listed here...</b></div>
     <?php } ?>
    </body>
    </html>
    x.php
    Code:
    <html>
    <head>
    
    <script>
    function xxx(str) {
        if (str == "") {
            document.getElementById("txtHint").innerHTML = "";
            return;
        } else {
            if (window.XMLHttpRequest) {
                // code for IE7+, Firefox, Chrome, Opera, Safari
                xmlhttp = new XMLHttpRequest();
            } else {
                // code f	or IE6, IE5
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            xmlhttp.onreadystatechange = function() {
    			document.write("kkshan");
                if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                    document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
                }
            }
            xmlhttp.open("GET","z.php?q="+str,true);
            xmlhttp.send();
        }
    }
    </script>
    </head>
    <body>
    
    <?php
     require_once('includes/load.php');
    $q = $_GET['q'];
    //echo $q;
    //exit;
    if ($q=="1"){$q=" branch between '01' and '50'";}
    elseif ($q=="2"){$q=" branch between '51' and '88'";}
    else{$q=" 1=1";}
    
    $sql="SELECT * FROM branch WHERE ".$q." and brname<>' '";
    //ECHO $sql;
    //EXIT;
    $result = mysqli_query($con,$sql);
    ?>
    
    </head>
    <body>
    
    <form method="post" class="clearfix">
    <select name="branch" onchange="xxx(this.value)">
     <option value="">Select a branch:</option>
    
     <?php
    
    while($file = mysqli_fetch_array($result)) {
    	?>
    	  
      <option value="<?php echo $file['BRANCH'];?>"><?php echo $file['BRNAME'];?></option>
      <?PHP
    	}
    	
    mysqli_close($con);
    ?>
    </select>
    </form>
    </body>
    </html>
    z.php
    Code:
    <html>
    <body>
    
    
    <?php
    
     require_once('includes/load.php');
    $q =$_GET['q'];
    
    
    
    $sql="SELECT * FROM maymst WHERE branch='".$q."'";
    //ECHO $sql;
    //EXIT;
    $result = mysqli_query($con,$sql);
    ?>
    
     <select name="staff">
     <option value="">Select a person:</option>
    
     <?php
    
    while($file = mysqli_fetch_array($result)) {
    	?>
    	  
      <option value="<?php echo $file['DESG'];?>"><?php echo $file['DESG'];?></option>
      <?PHP
    	}
    mysqli_close($con);
    ?>
    </select>
    </body>
    </html>
Working...