Jump to content

[HELP] User Login Based On Country/Territory


dabluwt

Recommended Posts

Hi, wish somebody can help me T_T

I'm little bit confused how to make user log-in based on country or territory, what I'm talking about is like this:

The User table is:

id_user | username | password | level | id_country

The Country table is:

id | country_name

And when user login, there's a data entry form and there is a drop-down/combo-box in a form, that filled with user countries, like this:

Country: [____] --> This part is automatically filled/disabled field if a user log-in with their username based on level and countries.

Province: [____] --> This is a chained combo-box from countries

City: [____] --> Also this chained to Province

What I mean is, when user's log-in with their country id, so the "Country Combo-Box" will be automatically filled and disabled. So user can't choose another country, only their country based on username and territories.

Thank you for all your help.

Best regards,

Kris

I have this scripts:

 

login_form.php

<div><center>
<form name="logForm" method="post" action="login_validation.php">
<table class="table-list" width="500" border="0" cellpadding="2" cellspacing="1" bgcolor="#999999">
<tr>
<td width="106" rowspan="5" align="center" bgcolor="#CCCCCC"><img src="images/padlock.png" width="116" height="75" /></td>
<th colspan="2" bgcolor="#CCCCCC"><b>LOGIN FORM </b></td> 
</tr>
<tr>
<td width="117" bgcolor="#FFFFFF"><b>Username</b></td>
<td width="263" bgcolor="#FFFFFF"><b>: 
<input name="txtUser" type="text" size="30" maxlength="20" />
</b></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"><b>Password</b></td>
<td bgcolor="#FFFFFF"><b>: 
<input name="txtPassword" type="password" size="30" maxlength="20" />
</b></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"><b>Access Level</b></td>
<td bgcolor="#FFFFFF"><b>:
<select name="comboLevel">
<option value="BLANK">- Choose -</option>
<?php
$level = array("operator", "admin");
foreach ($level as $p) {
if ($_POST['comboLevel']==$p) {
$check="selected";
} else { $check = ""; }
echo "<option value='$p' $check>$p</option>";
}
?>
</select>
</b></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"> </td>
<td bgcolor="#FFFFFF"><input type="submit" name="btnLogin" value=" Login " /></td>
</tr>
</table>
</form>
</center></div>

and this validation script:

login_validation.php

<?php 
if(isset($_POST['btnLogin'])){
$msgError = array();
if ( trim($_POST['txtUser'])=="") {
$pesanError[] = "Username </b> cannot empty !";	
}
if (trim($_POST['txtPassword'])=="") {
$msgError[] = "Password </b> cannot empty !";	
}
if (trim($_POST['comboLevel'])=="BLANK") {
$msgError[] = "Level</b> not picked !";	
}

$txtUser = $_POST['txtUser'];
$txtUser = str_replace("'","´",$txtUser);

$txtPassword=$_POST['txtPassword'];
$txtPassword= str_replace("'","´",$txtPassword);

$comboLevel	=$_POST['comboLevel'];

if (count($msgError)>=1 ){
echo "<div class='mssgBox'>";
echo "<img src='images/exclamation.png'> <br><hr>";
$noMsg=0;
foreach ($msgError as $index=>$show_msg) { 
$noMsg++;
echo "   $noMsg. $show_msg<br>";	
} 
echo "</div> <br>"; 



include "login.php";
}
else {

$loginSql = "SELECT * FROM user WHERE username='".$txtUser."' 
AND password='".md5($txtPassword)."' AND level='$comboLevel'";
$loginQry = mysql_query($loginSql, $conndb) 
or die ("Query Error : ".mysql_error());


if (mysql_num_rows($loginQry) >=1) {
$loginData = mysql_fetch_array($loginQry);
$_SESSION['SES_LOGIN'] = $loginData['id_user']; 
$_SESSION['SES_USER'] = $loginData['username']; 


if($comboLevel=="admin") {
$_SESSION['SES_ADMIN'] = "admin";
}


if($comboLevel=="operator") {
$_SESSION['SES_OPERATOR'] = "operator";
}

// Refresh
echo "<meta http-equiv='refresh' content='0; url=?page=Main-Page'>";
}
else {
echo "You Not Login As ".$_POST['comboLevel'];
}
}
} 
?>

Thank you for all help.... T_T thank you..

Link to comment
Share on other sites

And this my select combo-box form/script:

<tr>
      <td><strong>Country </strong></td>
      <td><strong>:</strong></td>
      <td><select name="cmbcountry" id="country">
          <option value="BLANK">....</option>
          <?php
	  $dataSql = "SELECT * FROM country ORDER BY id_country";
	  $dataQry = mysql_query($dataSql, $koneksidb) or die ("Fail to query".mysql_error());
	  while ($dataRow = mysql_fetch_array($dataQry)) {
	  	if ($datacountry == $dataRow['id_country']) {
			$cek = " selected";
		} else { $cek=""; }
	  	echo "<option value='$dataRow[id_country]' $cek>$dataRow[country_name]</option>";
	  }
	  $sqlData ="";
	  ?>
      </select>      </td>
    </tr>
Link to comment
Share on other sites

What do you collect province and city for if they do not have tables in the DB? What does a users city / country have to do with his login data?

The connection is there are user's from different countries, so when they log-in they don't have to choose their country again because it will be automatically filled if they log-in, so they can't messed up or entry a data from other country.

 

For example: Mr. White is from Nigeria, and Mr. John from England, so if both of them log-in they cannot choose other country, they only can fill their own data based on their countries.

 

Because if Mr. White log-in and he can choose "England" from the Country ComboBox, Mr. John will be confused whose filling the data from England, because he is from England, and there is no other user besides him. That's why I want to make the application like that :)

 

Here the example picture:

 

 

 

xpn4m1.jpg

 

 

 

or this

 

 

 

r91rh0.jpg

 

 

 

 

Someone asked me, why do you user ComboBox if user can't choose? The answer is: Because I have three ComboBox that connected each one of another (Multi Chainned ComboBox). If a user log-in then the first ComboBox will be disabled and automatically filled in with the user country, all they have to do is choosing the Province and City.

 

Hope you can help me...

Edited by dabluwt
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.