#1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2009
    Posts
    721
    Rep Power
    7

    Live MySQL attempt not working


    Howdy y'all. I am trying to run a quick MySQL query and build/populate 2 text boxes with the returned value, and have it post to the page. If I run the query indepedantly, it runs just fine. If I try the drop-down, I get no errors in my browser's console, yet the text boxes do not come to exist. Anything I might be missing?

    Drop-down w/ following DIV the returning echo SHOULD arrive in...
    Code:
                                  <TABLE id="sick" style="display: none;">
                                    <TR>
                                      <TD style="text-align: right;width: 110px;"><H3>Name:&nbsp;</H3></TD>
                                      <TD colspan="2">
                                        <SELECT style="width: 150px;" onchange="live(this.value)">
                                          <OPTION>Select a name...</OPTION>
                                          <OPTION value="msanchez">Someone</OPTION>
                                        </SELECT>
                                      </TD>
                                    </TR>
                                    <DIV id="userInfo">
                                    </DIV>
                                  </TABLE>
    Function build...
    Code:
                            function live(str) {
                              if (str=="") {
                                document.getElementById("userInfo").innerHTML="";
                                return;
                              } 
                              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("userInfo").innerHTML=xmlhttp.responseText;
                                }
                              }
                              xmlhttp.open("GET","live.php?q="+str,true);
                              xmlhttp.send();
                            }
    And the live.php to run this process...
    PHP Code:
    <?php
      $q
    =$_GET["q"];
       
      
    $statement $link->prepare("SELECT `Department`, `Manager` FROM `userpass` WHERE `Username` = '?'");
      
    $statement->bind_param('s'$q);
      
    $statement->execute();
      
    $statement->bind_result($col1,$col2);
      while (
    $statement->fetch()) {
        
    $var['department'] = $col1;
        
    $var['manager'] = $col2;
      }
      
    $statement->close();
       
      echo 
    '                                <TR>
                                      <TD style="text-align: right;"><H3>Department:&nbsp;</H3></TD>
                                      <TD colspan="2">
                                        <INPUT type="text" name="dept" value="' 
    $var['department'] . 's" disabled />
                                      </TD>
                                    </TR>
                                    <TR>
                                      <TD style="text-align: right;"><H3>Manager:&nbsp;</H3></TD>
                                      <TD colspan="2">
                                        <INPUT type="text" name="mgr" value="' 
    $var['manager'] . '" disabled />
                                      </TD>
                                    </TR>'
    ;   
    ?>
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2009
    Posts
    721
    Rep Power
    7
    Wow, never mind. I forgot that my whole site runs through a base file at the root, but I'm calling a file on it's own here, so I didn't define its location right. Sorry all!
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2009
    Posts
    721
    Rep Power
    7
    Thanks all.
    Last edited by Triple_Nothing; April 3rd, 2013 at 02:38 PM.

IMN logo majestic logo threadwatch logo seochat tools logo