i have a dropdown box and i already upload the value from dropdown selection to database. after uploading i want to cange the dropdown value how should i do,please help me.

thanks in advance

3 Years
Discussion Span
Last Post by malatamil

Show your code so far and give and example of what you want to see.


this code is to upload values to database table.

<select id="city" name="city" onChange="getPlace(this.value)">
        <option value="" selected="selected">... Select City ...</option>
                $query = "SELECT `state_id`, `state` FROM `states` ";
                $result = mysql_query($query);

    //echo mysql_error();
    while($rows = mysql_fetch_array($result))
    $selected = "";
    $categoryId = $rows['state_id'];
    $categoryName = $rows['state'];
    if($catid == $categoryId)
    $selected = "selected";
            <option value="<?php echo $categoryId; ?>" <?php echo $selected; ?> ><?php echo $categoryName; ?></option>
            <?php } ?>
<div align="left" id="citydiv">

and javascript to display checkbox value

function getPlace(stateId) {        

        var strURL="findplace.php?city="+stateId;
        var req = getXMLHTTP();

        if (req) {

            req.onreadystatechange = function() {
                if (req.readyState == 4) {
                    // only if "OK"
                    if (req.status == 200) {                        
                    } else {
                        alert("There was a problem while using XMLHTTP:\n" + req.statusText);
            req.open("GET", strURL, true);


<? $city=intval($_GET['city']);
$query="SELECT `city_id`, `city` FROM `cities` WHERE `state_id`='$city'";

<td><div align="left">Place:</div></td><td>

<? while($row=mysql_fetch_array($result)) { ?>
<input type="checkbox"  name="place[]" value="<?=$row['city_id']?>" /><?=$row['city']?>

<? } ?>

$lid= mysql_insert_id();                   

            //cityid and placeid added here
            $cityid = trim(ucwords(strtolower(mysql_real_escape_string($_POST['city']))));
            foreach($_POST["place"] as $i=>$value) 
                $sql3 = mysql_query("INSERT INTO `city_place`(`city_id`, `place_id`, `spaid`) VALUES ('$cityid','$value',$lid)");

after uploading in edit page i want to show the selected value in dropdown selection and checkbox selected value only,then if i want to change the selected value i should select from dropdown and checkbox


i have no idea about update values in dropdownbox and checkbox. above i have added insert query to database. so please guide me. i tried but am not getting exactly.where i have to add ajax call function and how to use it for selected cities and also non selected cities in checkbox based on dropdown menu selection. in dropdown menu i want to show only one city and in checkbox to show both selected and non selected cities.

 <?php $sql3 = mysql_query("SELECT s.id,cp.`id`, cp.`state_id`, cp.`city_id`, cp.`spaid`,c.city,st.state FROM spa s 
                LEFT JOIN `city_place` cp ON cp.spaid=s.id
                LEFT JOIN states st ON st.state_id=cp.state_id
                LEFT JOIN cities c ON c.city_id=cp.city_id
                 WHERE s.id='$id' LIMIT 0,1");
                while($c = mysql_fetch_array($sql3))

                <tr><td>City: </td><td><select name="city" id="city" onChange="getPlace(this.value)">
                <option value="" selected="selected"><?php echo $c['state']; ?></option>
            <?php } ?>

            <tr><td><div id="placediv">
                <ul class="subcat_tick">
                    <? while($row = mysql_fetch_array($sql11))
                    $state_id = $row['state_id'];
                    $city_id = $row['city_id'];
                    $checked = (is_null($city_id)) ? '' : " checked";  ?>
                    <input name='place[$state_id]' type='checkbox'$checked /> <span><?=$row['city']?></span>

                    <? } ?>

Edited by malatamil: updation

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.