Justin_22 0 Newbie Poster

Hi, I have an update page to update the data that are stored in the database. The page is able to extract all the data from the database that are stored. The select option is dynamic dependent select option. I am facing the following issues:
1) select option correctly extracted the data but it does not shows other option
2) select option is showing the ID instead of the value

Below is my code for update page

<script src="jquery.min.js"></script>

<script type="text/javascript">
    $(document).ready(function () {
        $('#brand').on('change', function () {
            var brandID = $(this).val();
            if (brandID) {
                $.ajax({
                    type: 'GET',
                    url: 'getBrand.php',
                    data: 'brandID=' + brandID,
                    success: function (html) {
                        $('#type').html(html);
                        $('#model').html('<option value="">Select type first</option>');
                    }
                });
            } else {
                $('#brand').html('<option value="">Select type first</option>');
                $('#model').html('<option value="">Select brand first</option>');
            }
        });

        $('#type').on('change', function () {
            var typeID = $(this).val();
            if (typeID) {
                $.ajax({
                    type: 'GET',
                    url: 'getBrand.php',
                    data: 'typeID=' + typeID,
                    success: function (html) {
                        $('#model').html(html);
                    }
                });
            } else {
                $('#model').html('<option value="">Select type first</option>');
            }
        });
    });
</script>

<?php
include('dbConfig.php');
$id = $_GET["id"];

$query = ("SELECT * FROM cardetails cd, brand b, type t, model m where cd.brandName = b.brandID and cd.type = t.typeID and cd.model = m.modelID and carID = $id");
$result = executeSelectQuery($query);

for ($i = 0; $i < count($result); $i++) {
    $carID = $result[$i]['carID'];
    $brandName = $result[$i]['brandName'];
    $type = $result[$i]['type'];
    $model = $result[$i]['model'];
    $price = $result[$i]['price'];
    $details = $result[$i]['details'];
}
?>

<h2>Update Car Details</h2>

<form name='updating' method='post' action='updateDetails.php' >
    <table style='width: 50%'>
        <tr><td colspan='2'>&nbsp;</td></tr>
        <tr>
            <td>Car ID</td>
            <td><input type='text' name="carID" style="width: 270px; height: 30px" readonly value="<?php echo $result[0]['carID']; ?>"></td>
        </tr>
        <tr><td colspan='2'>&nbsp;</td></tr>
        <tr>
            <td>Brand</td>
            <td>
                <?php
                $query1 = "SELECT * FROM brand b, cardetails cd where b.brandID = cd.brandName and cd.carID = $carID";
                $result1 = mysqli_query($link, $query1) or die(mysqli_error($link));

                echo "<select name='brandName' id='brandName' style='width: 270px'>";
                while ($row = mysqli_fetch_array($result1)) {
                    $isSelected = ($result1 === $brandName) ? " selected" : "";
                    echo "<option value='" . $row['brandID'] . " '>" . $row['brandName'] . "</option>";
                }
                echo "</select>";
                ?>

        </tr>
        <tr><td>&nbsp;</td><td>&nbsp;</td></tr>
        <tr>
            <td>Type</td>
            <td><?php
                $query2 = "SELECT * FROM type t, cardetails cd where cd.carID = $carID";
                $result2 = mysqli_query($link, $query2) or die(mysqli_error($link));

                echo "<select name='type' id='type' style='width: 270px'>";
                while ($row = mysqli_fetch_array($result2)) {
                    $isSelected = ($result2 === $type) ? " selected" : "";
                    echo "<option value='" . $row['typeID'] . " '>" . $row['type'] . "</option>";
                }
                echo "</select>";
                ?>

            </td>
        </tr>
        <tr><td>&nbsp;</td><td>&nbsp;</td></tr>
        <tr>
            <td>Model</td>
            <td><?php
                $query3 = "SELECT * FROM model m, cardetails cd where cd.carID = $carID";
                $result3 = mysqli_query($link, $query3) or die(mysqli_error($link));

                echo "<select name='model' id='model' style='width: 270px'>";
                while ($row = mysqli_fetch_array($result3)) {
                    $isSelected = ($result3 === $model) ? " selected" : "";
                    echo "<option value='" . $row['modelID'] . " '>" . $row['model'] . "</option>";
                }
                echo "</select>";
                ?></td>
        </tr>
        <tr><td>&nbsp;</td><td>&nbsp;</td></tr>
        <tr>
            <td>Price</td>
            <td><input type='text' name="price" style="width: 270px; height: 30px" value="<?php echo $result[0]['price']; ?>"></td>
        </tr>
        <tr><td>&nbsp;</td><td>&nbsp;</td></tr>
        <tr>
            <td>Details</td>
            <td><textarea name="details" rows='8' cols='50' style="width: 270px" ><?php echo $result[0]['details']; ?></textarea></td>
        </tr>

        <tr><td>&nbsp;</td><td>&nbsp;</td></tr>
        <tr align='center'><td><input type='submit' value='Update Car Details'></form></td>

            </form>

        <tr><td>&nbsp;</td><td>&nbsp;</td></tr>
    </table>

Below is another set of code for other select option

<?php
include('dbConfig.php');

if(isset($_GET["brandID"]) && !empty($_GET["brandID"])){
    $query = $link->query("SELECT * FROM type WHERE brandID = ".$_GET['brandID']." ");
    $rowCount = $query->num_rows;
    if($rowCount > 0){
        echo '<option value="">Select Type</option>';
        while($row = $query->fetch_assoc()){ 
            echo '<option value="'.$row['typeID'].'">'.$row['type'].'</option>';
        }
    }else{
        echo '<option value="">Type not available</option>';
    }
}

if(isset($_GET["typeID"]) && !empty($_GET["typeID"])){
    $query = $link->query("SELECT * FROM model WHERE typeID = ".$_GET['typeID']." ");
    $rowCount = $query->num_rows;
    if($rowCount > 0){
        echo '<option value="">Select Model</option>';
        while($row = $query->fetch_assoc()){ 
            echo '<option value="'.$row['modelID'].'">'.$row['model'].'</option>';
        }
    }else{
        echo '<option value="">Model not available</option>';
    }
}
?>