0

I'm trying to get the text value from a select dropdown menu that is populated by a database using the following function:

<?php
function searchintspokenlang()
{
require ('../../../connect_db.php');
    $queryintspoken="SELECT Language FROM languages";
    $result=mysqli_query($dbc, $queryintspoken);    

        while ($row = mysqli_fetch_array($result))  
        {
        echo "<option value='" . $row['Language'] . "'>" . $row['Language'] . "</option>";
        }

}
?>

Which is called on the html page:

</head> <h1 id ="header1">Select Intepreter by written or spoken language</h1> <div id = "spokenlang"> <form> <select id = 'searchspokenlang' name='searchspokenlang' onchange='getintspoken(this.value)'> <?php
 include ('functions.php');
 searchintspokenlang();
    ?> </select>

I have then have the following AJAX function, that i found on W3C schools which does exactly what i want which is generate a dyanamic table based on getspokenlang.php:

<script>
function getintspoken(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 (this.readyState == 4 && this.status == 200) {
                document.getElementById("txtHint").innerHTML = this.responseText;
            }
        };
        xmlhttp.open("GET","getspokenlang.php?s="+str,true);
        xmlhttp.send();
    }
}
</script>

The following is the php page getspokenlang.php that has the queries and the table i want to generate based on the dropdown selection:

<div class="tab_container"> <div id="tab1" class="tab_content"> <table class="tablesorternew" cellspacing="0"> <thead> <tr> <th>Company</th> <th>FirstName</th> <th>Surname</th> <th>StreetAddress</th> <th>NativeLanguage</th> <th>Email</th> <th>Mobile</th> <th>Landline</th><td> </tr> </thead> <tbody> <?php  
    $s = intval($_POST['s']);

$querygetspokenlang="SELECT * FROM spokenlang WHERE SpokenLang = '".$s."'";
$intspokenlangid=mysqli_query($dbc, $querygetspokenlang);
while ($row = mysqli_fetch_array($intspokenlangid)) {
$intspoken = $row['InterpreterID'];
echo $intspoken;

$querygetintspokenlang="SELECT * FROM interpreters WHERE InterpreterID = '".$intspoken."' ";
$result=mysqli_query($dbc, $querygetintspokenlang);
while($newArray = mysqli_fetch_array($result)){

$intid = $newArray['InterpreterID'];
$company = $newArray['BusinessName'];  
$firstname = $newArray['FirstName'];
$lastname = $newArray['Surname'];  
$address1 = $newArray['AddressL1'];  
$address2 = $newArray['AddressL2'];  
$address3 = $newArray['AddressL3']; 
$city = $newArray['TownCity'];  
$postcode = $newArray['Postcode']; 
$nativelanguage = $newArray['NativeLanguage'];    
$email = $newArray['Email'];
$mobile = $newArray['Mobile'];  
$landline = $newArray['Landline']; 

         echo "<tr><td>$company</td><td>$firstname</td><td>$lastname</td><td>$address1 $address2 $address3 $city $postcode</td><td>$nativelanguage</td><td>$email</td><td>$mobile</td><td>$landline</td>";
         echo "<td><a href=\"editint.php?InterpreterID=$intid\"><input type='image' src='images/icn_edit.png' title='Open'></td></tr>\n";
            }
}
?> </tbody> </table> </div> </div> <?php

    } //end if session set

    else {
        echo "Session expired";
    include ('login.php');}

?>

The problem i'm having is that it doesn't work and echoing the incoming variable only gives me a "0" regardless of the selection, i want to post the text in the dropdown to the getspokenlang.php page so i can run the query.

Please help,

Edited by Rishi_3

4
Contributors
3
Replies
38
Views
11 Months
Discussion Span
Last Post by James_62
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.