Note that there are some explanatory texts on larger screens.

plurals
  1. POhow I get city id from a php page
    primarykey
    data
    text
    <p>I am creating a registration form for my web site. In my registration form, there are two select boxes to select user's district and there city. So I need to do it, when a user select their district then automatically display city select box with cities which relevant to above selected district. To do this I used AJAX and PHP. I used findcity.php page to display the city in my register.php page. My problem is when I am try to get city id from the register.php page I cant get it. It I need to get to send with other data from register.php page to database. </p> <p>from my register.php page </p> <pre><code>&lt;div&gt; &lt;label for="district"&gt;District &lt;img src="../images/required_star.png" alt="required" /&gt; : &lt;/label&gt; &lt;?php require_once ('../includes/config.inc.php'); require_once( MYSQL2 ); $query="select * from district order by district_id"; $result = mysqli_query( $dbc, $query); echo '&lt;select name="district" class="text" onChange="getCity(' . "'" . 'findcity.php?district=' . "'" . '+this.value)"&gt;'; echo '&lt;option value=""&gt;-- Select District --&lt;/option&gt;'; while( $row = mysqli_fetch_array($result, MYSQLI_NUM)) { echo '&lt;option value="' . $row[0] . '"'; // Check for stickyness: if ( isset( $_POST['district']) &amp;&amp; ( $_POST['district'] == $row[0] )) echo ' selected="selected"'; echo " &gt;$row[1]&lt;/option&gt;"; } echo '&lt;/select&gt;'; ?&gt; &lt;/div&gt; &lt;div&gt; &lt;label for="city"&gt;City &lt;img src="../images/required_star.png" alt="required" /&gt; : &lt;/label&gt; &lt;input type="hidden" name="reg_locationid" id="reg_locationid" value="56" /&gt; &lt;div id="citydiv" style="position: relative; top: -14px; left: 130px; margin-bottom: -26px;"&gt; &lt;select name="city" class="text"&gt; &lt;option&gt;-- Select City --&lt;/option&gt; &lt;/select&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>this is findcity.php page </p> <pre><code>&lt;?php $districtId=$_GET['district']; require_once ('../includes/configaration.inc.php'); require_once( MYSQLCONNECTION ); $query="select city_id, city_name from city2 where district_id=$districtId"; $result=mysqli_query( $dbc, $query); echo '&lt;select name="city" class="text"&gt; &lt;option&gt;-- Select City --&lt;/option&gt;'; while($row=mysqli_fetch_array($result, MYSQLI_NUM)) { echo '&lt;option value="' . $row[0] . '"'; // Check for stickyness: if ( isset( $_POST['city']) &amp;&amp; ( $_POST['city'] == $row[0] )) { echo ' selected="selected"'; //echo '&lt;input type="hidden" name="city" value="' . $row[0] . '"'; } echo " &gt;$row[1]&lt;/option&gt;"; } echo '&lt;/select&gt;'; </code></pre> <p>?></p> <p>this is my ajax functions </p> <pre><code>function getXMLHTTP() { //function to return the xml http object var xmlhttp=false; try{ xmlhttp=new XMLHttpRequest(); } catch(e) { try{ xmlhttp= new ActiveXObject("Microsoft.XMLHTTP"); } catch(e){ try{ xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e1){ xmlhttp=false; } } } return xmlhttp; } function getCity(strURL) { var req = getXMLHTTP(); if (req) { req.onreadystatechange = function() { if (req.readyState == 4) { // only if "OK" if (req.status == 200) { document.getElementById('citydiv').innerHTML=req.responseText; } else { alert("There was a problem while using XMLHTTP:\n" + req.statusText); } } } req.open("GET", strURL, true); req.send(null); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload