Jump to content

Get city id from ajax generating city select box to my original php page


thara

Recommended Posts

In my registration form there are many form elements to give users' details for registration in my web site. among those elements there are two select boxes for user to select their district and city. I have created these two select box using ajax. Therefor a user select a district then automatically ajax creating second select box for cities is populating. I used separate php page called findcity.php to create city select box. I called this findcity.php page from my original register.php page through onChange attribute. and there I passed the district id with the url to findcity.php page. like wise,

 

Now I need to bring city id to my original register.php page when user select a city from city select box in findcity.php page. my problem is that. I tried to get city Id to register.php page but still I couldn't get it. city id is needed me to send to the database with other form elements' values.

 

can anybody help me to fix my problem?

 

here is my coding for your reference.

 

This code is, from my register.php page

 

<div>
<label for="district">District <img src="../images/required_star.png" alt="required" /> : </label>
<?php

require_once ('../includes/config.inc.php');    
require_once( MYSQL2 );

$query="select * from district order by district_id";
$result = mysqli_query( $dbc, $query);

    echo '<select name="district" class="text" onChange="getCity(' . "'" . 'findcity.php?district=' . "'" . '+this.value)">';
    echo '<option value="">-- Select District --</option>';

    while( $row = mysqli_fetch_array($result, MYSQLI_NUM)) { 
        echo '<option value="' . $row[0] . '"';

        // Check for stickyness: 
        if ( isset( $_POST['district']) && ( $_POST['district'] == $row[0] ))    
            echo ' selected="selected"';

            echo " >$row[1]</option>";    
    }
    echo '</select>';
?> 

</div>    
<div>
<label for="city">City <img src="../images/required_star.png" alt="required" /> : </label>
<input type="hidden" name="reg_locationid" id="reg_locationid" value="56" />
<div id="citydiv" style="position: relative; top: -14px; left: 130px; margin-bottom: -26px;">
    <select name="city" class="text">
        <option>-- Select City --</option>
    </select>
</div>
</div>

 

this is, from my findcity.php page

 

<?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 '<select name="city" class="text">
    <option>-- Select City --</option>';

while($row=mysqli_fetch_array($result, MYSQLI_NUM)) { 

echo '<option value="' . $row[0] . '"';

// Check for stickyness: 
if ( isset( $_POST['city']) && ( $_POST['city'] == $row[0] )) { 
    echo ' selected="selected"';

    //echo '<input type="hidden" name="city"  value="' . $row[0] . '"'; 

}
    echo " >$row[1]</option>";  

}

echo '</select>';

?>

 

 

Link to comment
Share on other sites

thank for your reply...

 

I have done it in my findcity.php page

 

echo '<option value="' . $row[0] . '"';

// Check for stickyness: 
if ( isset( $_POST['city']) && ( $_POST['city'] == $row[0] )) { 
    echo ' selected="selected"';


}
    echo " >$row[1]</option>";  

 

but my problem is how can I get that id value to my register php page...

 

Link to comment
Share on other sites

thank for your reply...

 

I have done it in my findcity.php page

 

echo '<option value="' . $row[0] . '"';

// Check for stickyness: 
if ( isset( $_POST['city']) && ( $_POST['city'] == $row[0] )) { 
    echo ' selected="selected"';


}
    echo " >$row[1]</option>";  

 

but my problem is how can I get that id value to my register php page...

 

You need to update the options using javascript, by passing the data back during your ajax request. Once a php page is finished loading you can consider it just a plain html page, that means, no more php processing will take place until a subsequent load of the page. That means you are going to pass the data back from your findcity.php page, using the ajax request then loop over the results in Javascript to update the field.

 

Also, you probably don't want to format the data on your findcity.php page, that will take longer to send over an httprequest. Just send back the data you need as a JSON Object.

findcity.php example:

<?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);

$jsonarray = array();
foreach( $result as $row ){
   $jsonarray[$row['id']] = $row['name'];
}

print json_encode( $jsonarray );

?>

 

Then back on register.php you will have js parse the data from the JSON response and update the select box.

 

Show me your ajax request and a print_r( $result ) on your findcity.php and I can give you some more specific guidance.

Link to comment
Share on other sites

this is my print_r( $result )  result in findcity.php page

 

mysqli_result Object

(

    [current_field] => 0

    [field_count] => 2

    [lengths] =>

    [num_rows] => 2

    [type] => 0

)

 

 

this is ajax functions

 

function getXMLHTTP() { //fuction 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) {		
   // alert(req.responseText);					
					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);
	}

}

Link to comment
Share on other sites

<?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);

$jsonarray = array();
//I messed up here - new code below
while( $row=mysqli_fetch_array($result, MYSQLI_NUM) ){
$jsonarray[$row[0]] = $row[1];
}

print json_encode( $jsonarray );

?>

 

So now you have a nicely sorted JSON object where the key is the id of the city and the value is the city name.

 

Then all you need to do is loop over the responseText as a JSON object and build your output using js.

function getXMLHTTP() { //fuction 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) {		
   // alert(req.responseText);					
					var jsonresponse = eval("("+req.responseText+")");						
				} else {
					alert("There was a problem while using XMLHTTP:\n" + req.statusText);
				}
			}				
		}			
		req.open("GET", strURL, true);
		req.send(null);
	}

}

        //NOW YOU HAVE YOUR DATA IN A NICE JS OBJECT CALLED JSONRESPONSE
        output = '';
        output   += '<option>-- Select City --</option>';
        for (var key in jsonresponse) {
          output += '<option value="'+key+'">'+jsonresponse[key]+'</option>';
        }
        //I would add in id to the <select> like <select id="citylist">
        document.getElementById('citylist').innerHTML(output);

I didn't test that, but it should be close. Let me know if it works.

Link to comment
Share on other sites

I did like that ... now my city select box is not populating. It just only display. when i select a district in my first select box second one happen nothing.

where is the wrong????

 

this is my modified findcity.php page..

 

<?php



require_once ('../includes/config.inc.php');	
require_once( MYSQL2 );

$districtId=$_GET['district'];	

//if($districtId!=""){ 	

	$query="select city_id, city_name from city2 where district_id=$districtId";
	$result=mysqli_query( $dbc, $query);



    //die($query);

	//echo '<select name="city" class="text">
			//<option>-- Select City --</option>';

	//while($row=mysqli_fetch_array($result, MYSQLI_ASSOC)) { 

		//echo '<option value="' . $row[0] . '"';

		// Check for stickyness: 
		//if ( isset( $_POST['city']) && ( $_POST['city'] == $row[0] )) {	
			//echo ' selected="selected"';

			//echo '<input type="hidden" name="city"  value="' . $row[0] . '"';	

		//}	echo " >$row[1]</option>";	
		    //die($row[0] . ' ' . $row[1]);
		//echo "<option value='" . $row['city_id'] . "'>" . $row['city_name'] . "</option>"; 

	//}

	//echo '</select>';

$jsonarray = array();
//I messed up here - new code below
while( $row=mysqli_fetch_array($result, MYSQLI_NUM) ){
$jsonarray[$row[0]] = $row[1];
}

print json_encode( $jsonarray );



//}
?>

Link to comment
Share on other sites

I did like that ... now my city select box is not populating. It just only display. when i select a district in my first select box second one happen nothing.

where is the wrong????

 

this is my modified findcity.php page..

 

<?php



require_once ('../includes/config.inc.php');	
require_once( MYSQL2 );

$districtId=$_GET['district'];	

//if($districtId!=""){ 	

	$query="select city_id, city_name from city2 where district_id=$districtId";
	$result=mysqli_query( $dbc, $query);



    //die($query);

	//echo '<select name="city" class="text">
			//<option>-- Select City --</option>';

	//while($row=mysqli_fetch_array($result, MYSQLI_ASSOC)) { 

		//echo '<option value="' . $row[0] . '"';

		// Check for stickyness: 
		//if ( isset( $_POST['city']) && ( $_POST['city'] == $row[0] )) {	
			//echo ' selected="selected"';

			//echo '<input type="hidden" name="city"  value="' . $row[0] . '"';	

		//}	echo " >$row[1]</option>";	
		    //die($row[0] . ' ' . $row[1]);
		//echo "<option value='" . $row['city_id'] . "'>" . $row['city_name'] . "</option>"; 

	//}

	//echo '</select>';

$jsonarray = array();
//I messed up here - new code below
while( $row=mysqli_fetch_array($result, MYSQLI_NUM) ){
$jsonarray[$row[0]] = $row[1];
}

print json_encode( $jsonarray );



//}
?>

try to alert the object in your ajax request js.

if (req.readyState == 4) {
				// only if "OK"
				if (req.status == 200) {		
   // alert(req.responseText);					
					var jsonresponse = eval("("+req.responseText+")");
                                                alert( jsonresponse );						
				} else {
					alert("There was a problem while using XMLHTTP:\n" + req.statusText);
				}
			}

Link to comment
Share on other sites

the output is only '[object Object]' in alert box...

 

when select a value from 1st select box the alert is prompting with text of '[object Object]'

Ok, that's good, that just means we need to make sure we are looping over the object properly, but we are sure that it was successfully created. Did you add the new js after the ajax function?

//NOW YOU HAVE YOUR DATA IN A NICE JS OBJECT CALLED JSONRESPONSE
        output = '';
        output   += '<option>-- Select City --</option>';
        for (var key in jsonresponse) {
          output += '<option value="'+key+'">'+jsonresponse[key]+'</option>';
        }
        //I would add in id to the <select> like <select id="citylist">
        //document.getElementById('citylist').innerHTML(output); <---- I MADE A MISTAKE HERE it should be innerHTML = output;
        document.getElementById('citylist').innerHTML = output;

Link to comment
Share on other sites

can I know.. what does this code mean???

 

        //I would add in id to the <select> like <select id="citylist">
        //document.getElementById('citylist').innerHTML(output); <---- I MADE A MISTAKE HERE it should be innerHTML = output;
        document.getElementById('citylist').innerHTML = output;

 

I can see only option tag in json object to generate city drop down box.. but there is no 'select' tag which need to create a dropdown list....

 

need i use select tag... then where?????

 

thank you...

Link to comment
Share on other sites

can I know.. what does this code mean???

 

        //I would add in id to the <select> like <select id="citylist">
        //document.getElementById('citylist').innerHTML(output); <---- I MADE A MISTAKE HERE it should be innerHTML = output;
        document.getElementById('citylist').innerHTML = output;

 

I can see only option tag in json object to generate city drop down box.. but there is no 'select' tag which need to create a dropdown list....

 

need i use select tag... then where?????

 

thank you...

The first two lines are comments, so you can see the process i'm going through and thoughts I think may be helpful, the 3rd line is actually code that sets the innerHTML of the <select> box to the output generated by the json object loop.

 

Post up your entire updated ajax code.

Link to comment
Share on other sites

This is my entire updated ajax page..

 

function getXMLHTTP() { //fuction 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) {		
   // alert(req.responseText);					
					var jsonresponse = eval("("+req.responseText+")");						
				} else {
					alert("There was a problem while using XMLHTTP:\n" + req.statusText);
				}
			}				
		}			
		req.open("GET", strURL, true);
		req.send(null);
	}

}

//NOW YOU HAVE YOUR DATA IN A NICE JS OBJECT CALLED JSONRESPONSE
        output = '';
        output   += '<option>-- Select City --</option>';
        for (var key in jsonresponse) {
          output += '<option value="'+key+'">'+jsonresponse[key]+'</option>';
        }
        //I would add in id to the <select> like <select id="citylist">
        //document.getElementById('citylist').innerHTML(output); <---- I MADE A MISTAKE HERE it should be innerHTML = output;
        document.getElementById('citylist').innerHTML = output;

Link to comment
Share on other sites

This is my entire updated ajax page..

 

function getXMLHTTP() { //fuction 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) {		
   // alert(req.responseText);					
					var jsonresponse = eval("("+req.responseText+")");						
				} else {
					alert("There was a problem while using XMLHTTP:\n" + req.statusText);
				}
			}				
		}			
		req.open("GET", strURL, true);
		req.send(null);
	}

}

//NOW YOU HAVE YOUR DATA IN A NICE JS OBJECT CALLED JSONRESPONSE
        output = '';
        output   += '<option>-- Select City --</option>';
        for (var key in jsonresponse) {
          output += '<option value="'+key+'">'+jsonresponse[key]+'</option>';
        }
        //I would add in id to the <select> like <select id="citylist">
        //document.getElementById('citylist').innerHTML(output); <---- I MADE A MISTAKE HERE it should be innerHTML = output;
        document.getElementById('citylist').innerHTML = output;

My bad the code at the bottom need to be inside the ajax function:

function getXMLHTTP() { //fuction 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) {		
   // alert(req.responseText);					
					var jsonresponse = eval("("+req.responseText+")");			
                                                var output = '';
                                                output   += '<option>-- Select City --</option>';
                                                for (var key in jsonresponse) {
                                                    output += '<option value="'+key+'">'+jsonresponse[key]+'</option>';
                                                }
                                                document.getElementById('citylist').innerHTML = output;			
				} else {
					alert("There was a problem while using XMLHTTP:\n" + req.statusText);
				}
			}				
		}			
		req.open("GET", strURL, true);
		req.send(null);
	}

}

Link to comment
Share on other sites

again city dropdown list is not populating. where are we going wrong???

 

this is my findcity php page

 

<?php



require_once ('../includes/config.inc.php');	
require_once( MYSQL2 );

$districtId=$_GET['district'];	

//if($districtId!=""){ 	

	$query="select city_id, city_name from city2 where district_id=$districtId";
	$result=mysqli_query( $dbc, $query);

    //die($query);

	//echo '<select name="city" class="text"  id="city" >
			//<option>-- Select City --</option>';

	//while($row=mysqli_fetch_array($result, MYSQLI_ASSOC)) { 

		//echo '<option value="' . $row[0] . '"';

		// Check for stickyness: 
		//if ( isset( $_POST['city']) && ( $_POST['city'] == $row[0] )) {	
			//echo ' selected="selected"';

			//echo '<input type="hidden" name="city"  value="' . $row[0] . '"';	

		//}	echo " >$row[1]</option>";	
		    //die($row[0] . ' ' . $row[1]);
		//echo "<option value='" . $row['city_id'] . "'>" . $row['city_name'] . "</option>"; 

	//}

	//echo '</select>';
//}

$jsonarray = array();
//I messed up here - new code below
while( $row=mysqli_fetch_array($result, MYSQLI_NUM) ){
$jsonarray[$row[0]] = $row[1];
}

print json_encode( $jsonarray );

?>

 

 

 

Link to comment
Share on other sites

this is a part of my register.php page... I am posting this your reference.

 

							<div>
							<label for="district">District <img src="../images/required_star.png" alt="required" /> : </label>
							<?php

								require_once ('../includes/config.inc.php');	
								require_once( MYSQL2 );

								$query="select * from district order by district_id";
								$result = mysqli_query( $dbc, $query);

									//echo '<select name="district" class="text" onChange="getCity(' . "'" . 'findcity.php?district=' . "'" . '+this.value)">';
									//echo '<select name="district" class="text" onChange="getCity(' . '\'findcity.php?district=\'+this.value+\'&city=\'' . '+document.getElementsByName(\'city\')[0].value)">';
									echo '<select name="district" class="text" id="district" onChange="getCity(' . "'" . 'findcity.php?district=' . "'" . '+this.value)">'; 
									echo '<option value="">-- Select District --</option>';

									while( $row = mysqli_fetch_array($result, MYSQLI_NUM)) { 
										echo '<option value="' . $row[0] . '"';

										// Check for stickyness: 
										if ( isset( $_POST['district']) && ( $_POST['district'] == $row[0] ))	
											echo ' selected="selected"';

											echo " >$row[1]</option>";	
									}
									echo '</select>';
							?> 

						</div>	
						<div>
							<label for="city">City <img src="../images/required_star.png" alt="required" /> : </label>
							<div id="citydiv" style="position: relative; top: -14px; left: 130px; margin-bottom: -26px;">
								<select name="city" class="text">
									<option>-- Select City --</option>
								</select>

							</div>
						</div>	

Link to comment
Share on other sites

again city dropdown list is not populating. where are we going wrong???

 

this is my findcity php page

 

<?php



require_once ('../includes/config.inc.php');	
require_once( MYSQL2 );

$districtId=$_GET['district'];	

//if($districtId!=""){ 	

	$query="select city_id, city_name from city2 where district_id=$districtId";
	$result=mysqli_query( $dbc, $query);

    //die($query);

	//echo '<select name="city" class="text"  id="city" >
			//<option>-- Select City --</option>';

	//while($row=mysqli_fetch_array($result, MYSQLI_ASSOC)) { 

		//echo '<option value="' . $row[0] . '"';

		// Check for stickyness: 
		//if ( isset( $_POST['city']) && ( $_POST['city'] == $row[0] )) {	
			//echo ' selected="selected"';

			//echo '<input type="hidden" name="city"  value="' . $row[0] . '"';	

		//}	echo " >$row[1]</option>";	
		    //die($row[0] . ' ' . $row[1]);
		//echo "<option value='" . $row['city_id'] . "'>" . $row['city_name'] . "</option>"; 

	//}

	//echo '</select>';
//}

$jsonarray = array();
//I messed up here - new code below
while( $row=mysqli_fetch_array($result, MYSQLI_NUM) ){
$jsonarray[$row[0]] = $row[1];
}

print json_encode( $jsonarray );

?>

 

Do you have a sample link to the page?

Link to comment
Share on other sites

its too, nothing happen dear.....

 

I did it like this

 

$jsonarray = array();
//I messed up here - new code below
while( $row=mysqli_fetch_array($result, MYSQLI_NUM) ){
$jsonarray[$row[0]] = $row[1];
}

echo '<pre>' . 
print_r( $jsonarray ) . 
  '</pre>';
  

print json_encode( $jsonarray );

 

 

Link to comment
Share on other sites

its too, nothing happen dear.....

 

I did it like this

 

$jsonarray = array();
//I messed up here - new code below
while( $row=mysqli_fetch_array($result, MYSQLI_NUM) ){
$jsonarray[$row[0]] = $row[1];
}

echo '<pre>' . 
print_r( $jsonarray ) . 
  '</pre>';
  

print json_encode( $jsonarray );

Just post up the files your using and we'll go from there.

Link to comment
Share on other sites

ok dear.. thank u very much for your cooperation.

 

This is my entire register.php page...

 

<?php

// Require the configuration before any PHP code as the configuration controls error reporting:
require ('../includes/config.inc.php');

$page_title = "Institute | Registration - Step 1";
include ('includes/header.html');

// Require the database connection:
require (MYSQL2);

// For storing registration errors:
$reg_errors = array();



// Check for a form submission:
//if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if ( isset( $_POST['submitted'])) {

// Check for a institute name:
if (preg_match ('/^[A-Z \'.-]{2,80}$/i', $_POST['ins_name'])) {
	$insName = mysqli_real_escape_string ($dbc, $_POST['ins_name']);
} else {
	$reg_errors['ins_name'] = 'Please enter your Institute name correctly!';
}

// Check for a institute slogan:
$Slogan = (!empty( $_POST['ins_slogan'])) ? mysqli_real_escape_string ( $dbc, $_POST['ins_slogan']) : NULL; 


// Check for the introduction note:
if (!empty($_POST['present_situation'])) {
	$present = mysqli_real_escape_string($dbc, strip_tags($_POST['present_situation']));
} else {
	$reg_errors['present_situation'] = 'Please enter a Note of present situation!';
}	

// Check for the address one:
if (!empty($_POST['address1'])) {
	$address1 = mysqli_real_escape_string($dbc, $_POST['address1']);
} else {
	$reg_errors['address1'] = 'Please enter a Address One correctly!';
}

// Check for a institute slogan:
$address2 = (!empty( $_POST['address2'])) ? mysqli_real_escape_string ( $dbc, $_POST['address2']) : NULL; 



// Check for a mobile number:
if ( is_numeric( $_POST['mobile'])) {
	$mobile = mysqli_real_escape_string ( $dbc, $_POST['mobile']);
} else {
	$reg_errors['mobile'] = 'Please enter a Mobile number correctly!';
} 	


// Check for an email address:
if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
	$email = mysqli_real_escape_string ($dbc, $_POST['email']);
} else {
	$reg_errors['email'] = 'Please enter a valid email address!';
}

// Check for a password and match against the confirmed password:
if (!empty($_POST['pass1'])) {
	if ($_POST['pass1'] == $_POST['pass2']) {
		$pass = mysqli_real_escape_string ($dbc, $_POST['pass1']);
	} else {
		$reg_errors['pass2'] = 'Your password did not match the confirmed password!';
	}
} else {
	$reg_errors['pass1'] = 'Please enter a valid password!';
}


if( isset( $_POST['district'])) {

	$district = $_POST['district'];
}



if (empty($reg_errors)) { // If everything's OK...

	// Make sure the email address and username are available:
	$q = "SELECT email FROM login WHERE email='$email'";
	$r = mysqli_query ($dbc, $q);

	// Get the number of rows returned:
	$rows = mysqli_num_rows($r);

	if ($rows == 0) { // No problems!

		echo 'there is no such a email';

		// Add the login details to the database...		
		$q = "INSERT INTO login (email, password, login_level, last_login) 
				VALUES ('$email', '"  .  get_password_hash($pass) .  "', 2, now() )"; 

		$r = mysqli_query ($dbc, $q);

		$loginId = mysqli_insert_id($dbc);

if ( $r ) {
	echo 'good';

	} else { echo 'bad';

	echo '<p>' . mysqli_error($dbc) . '<br />Query: ' . $q . '</p>'; // Debugging message.

}  			
	echo "<pre>"; 
		print_r($_POST)	;
	echo "</pre>";

	/* 
	-
	-
	-
	-
	-	here I need to get cityid from findcity page for database insertion..
	-
	-
	-
	-
	-
	-
	*/

		//if (mysqli_affected_rows($dbc) == 1) { // If it ran OK.
	} else { // The email address or username is not available.

		$reg_errors['email'] = 'This email address has already been registered. Try again with a different email';			

	} // End of $rows == 0 IF.
} // End of empty($reg_errors) IF.	
} // End of the main form submission conditional.
?>

	<div id="inner_wrapper">

		<div id="contents">

			<div id="content2">

				<h1>Tutor Registration</h1>

				<div style="height: 15px; background: #fff;" class="extra_top"></div>
				<div id="content_body">						

				<?php
					require ('/includes/form_functions.inc.php');
				?>					
					<h2>Basic Infomation</h2>

					<form name="centerRegister" action="register.php" method="post" accept-charset="utf-8" > 
					<p style="margin: -15px 0 10px 0; font-weight: normal;">Required fields are marked with <img src="../images/required_star.png" alt="required" /></p>

					<div class="group">
						<div>
							<label for="ins_name">Institute Name <img src="../images/required_star.png" alt="required" /> : </label>
							<?php create_form_input('ins_name', 'text', $reg_errors); ?>								
						</div>	
						<div>	
							<label for="ins_slogan">Institute Slogan : </label>
							<?php create_form_input('ins_slogan', 'text', $reg_errors); ?>
						</div>

					</div>

				</div>
				<div style="height: 15px; background: #fff;" class="extra_bottom"></div>
				<br /><div style="margin-bottom: 4px;"></div>			
				<div style="height: 15px; background: #fff;" class="extra_top"></div>
				<div id="content_body">						

					<h2>Contact Information</h2>

					<div class="group">

						<div>
							<label for="address1">Address 1 <img src="../images/required_star.png" alt="required" /> : </label>
							<?php create_form_input('address1', 'text', $reg_errors); ?>
						</div>							
						<div>
							<label for="address2">Address 2 : </label>
							<?php create_form_input('address2', 'text', $reg_errors); ?>
						</div>
						<div>
							<label for="district">District <img src="../images/required_star.png" alt="required" /> : </label>
							<?php

								require_once ('../includes/config.inc.php');	
								require_once( MYSQL2 );

								$query="select * from district order by district_id";
								$result = mysqli_query( $dbc, $query);

									//echo '<select name="district" class="text" onChange="getCity(' . "'" . 'findcity.php?district=' . "'" . '+this.value)">';
									//echo '<select name="district" class="text" onChange="getCity(' . '\'findcity.php?district=\'+this.value+\'&city=\'' . '+document.getElementsByName(\'city\')[0].value)">';
									echo '<select name="district" class="text" id="district" onChange="getCity(' . "'" . 'findcity.php?district=' . "'" . '+this.value)">'; 
									echo '<option value="">-- Select District --</option>';

									while( $row = mysqli_fetch_array($result, MYSQLI_NUM)) { 
										echo '<option value="' . $row[0] . '"';

										// Check for stickyness: 
										if ( isset( $_POST['district']) && ( $_POST['district'] == $row[0] ))	
											echo ' selected="selected"';

											echo " >$row[1]</option>";	
									}
									echo '</select>';
							?> 

						</div>	
						<div>
							<label for="city">City <img src="../images/required_star.png" alt="required" /> : </label>
							<div id="citydiv" style="position: relative; top: -14px; left: 130px; margin-bottom: -26px;">
								<select name="city" class="text">
									<option>-- Select City --</option>
								</select>

							</div>
						</div>								
						<div>
							<label for="mobile">Mobile <img src="../images/required_star.png"  alt="required" /> : </label>
							<?php create_form_input('mobile', 'text', $reg_errors); ?>								
						</div>
						<div>
							<label for="email">Email Address<img src="../images/required_star.png"  alt="required" /> : </label>
							<?php create_form_input('email', 'text', $reg_errors); ?>	
						</div>
						<div>
							<label for="pass1">Password <img src="../images/required_star.png"  alt="required" /> : </label>
							<?php create_form_input('pass1', 'password', $reg_errors); ?>								
						</div>
						<div>
							<label for="pass2">Conform Password <img src="../images/required_star.png"  alt="required" /> : </label>
							<?php create_form_input('pass2', 'password', $reg_errors); ?>								
						</div>
					</div>
				</div>

				<div id="content_body">						

					<div class="group">

						<div style="border-top: 1px dotted #bfbfbf; margin-top: 20px; padding: 8px 0;">
							<label> </label>
							<input type="submit"  name="submitted"  value="Register" class="formSubmit" />						

							<!-- <input type="hidden"   name="submitted"   value="TRUE" /> -->	
						</div>		

					</div>

					</form>
				</div>
				<div style="height: 15px; background: #fff;" class="extra_bottom"></div>



			</div>
		</div> <!-- end contents div -->
	</div> <!-- end inner_wrapper div --> 
</div> <!-- end wrapper1 div --> 

<?php
include ('includes/footer.html');
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.