i need a database connection for login for the different types
for the form below. I got it done for single type

<form>
<table border="0" width="300" height="180">
<tr><td colspan="2" height="20%"><b>Employee Login</b></td></tr>
<tr><td height="20%">Type:</td><td>
<select name="type"><option>Select One</option>
<option>Doctor</option>
<option>Nurse</option>
<option>Accountant</option>
<option>Security Officer</option>
<option>Administrator</option></select></td></tr>
<tr><td height="20%">Username:</td><td><input type="text" /></td></tr>
<tr><td height="20%">Password:</td><td><input type="password" /></td></tr>
<tr><td colspan="2" height="20%"><input type="image" src="images/login_sub.png" value="Login"</td></tr>
</table>
</form>

Recommended Answers

All 18 Replies

Please post your PHP code so we can lead you in the right direction.

Member Avatar for diafol

You need to explain further. A general login should suffice - can't see why you need a different one for each type.

You're database table would just include an extra column called 'type' to designate if they were a Doctor, Nurse, etc....

I agree with ardav, a simple login script will do just fine. Upon the sql query include a check for their 'type' and you're set.

Perhaps you could hire someone to get it done for you?

commented: agreed +5

You need to explain further.Or do you want each user to see something different when they log in ?

If so use this:

<?
session_start();

ob_start();
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="ping"; // Database name
$tbl_name="signeup"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("You are not authorized to use this system.");
mysql_select_db("$db_name")or die("You are not authorized to use this system. Contact the administrator");

// Define $myusername and $mypassword
$username=$_POST['username'];
//$username = sha1(username);
$password=$_POST['password'];
$password = sha1(password);

// To protect MySQL injection (more detail about MySQL injection)
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);

$sql="SELECT * FROM $tbl_name WHERE username='$username' and password='$password'";
				
				$result=mysql_query($sql);
				$qry_num = 0;
				$qry_result = mysql_QUERY($sql);  //select query\
				$qry_num = mysql_numrows($qry_result);
				$i = 0;

while($i < $qry_num) 
							 
					{
					$_SESSION['myid'] = mysql_result($qry_result,$i,"id");
					$_SESSION['reg_acc'] = mysql_result($qry_result,$i,"reg_acc");
					$_SESSION['hotel'] = mysql_result($qry_result,$i,"hotel");
					$_SESSION['piz_limit'] = mysql_result($qry_result,$i,"piz_limit");
					$i++;
					}


		
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $username and $password, table row must be 1 row

if($count==1){
// Register $username, $password and redirect to file "login_success.php"
session_register("username");
session_register("password");
header("location: useradmin/index.php");
}
else {
header("location: loginlin.php");
		}

ob_end_flush();
?>

I hope this is what you need, let see how it works out

Thanks very much. I don't think wanting to know details is wrong. I want differentiate the type of people loggi, that is the area in reb and how the restriction will be

<table width=100% border=0 cellpadding="0" cellspacing="0"> 


<!--<table width=100% border=0 cellpadding="0" cellspacing="0">-->

		

	<tr>
		<td class="passborder" colspan=3>&nbsp;</td>

	</tr>

	<tr>
		<td class="passborder" width=1%></td>
		<td class="passbody">
			<p><br>
			<center>

			
			<table border=0 cellpadding=0  cellspacing=0>
				<tr>

					<td><img src="images/mascot2_r.gif" border=0 width="1" height="1"></td>
					<td valign=top>
						<table cellspacing=0 class="passmaskframe">
							<tr>
								<td>
									<table cellpadding=20 cellspacing=0 class="passmask">
										<tr>
											<td>

												<p>
												<FORM action="appt_main_pass.php" method="post" name="passwindow" onSubmit="return pruf(this);">
													<div class="prompt">
														Password needed!<p>
													</div>
													<nobr>Username:</nobr>
													<br>
													<INPUT type="text" name="userid" size="14" maxlength="25"> <p>

													<nobr>Password:<br>
													<INPUT type="password" name="keyword" size="14" maxlength="25"><p>
													
													[B]<nobr>Type:<br>
													<select name="type">
													<option>Doctor</option>
													<option>Nurse</option>
													<option>Admin</option>
													<option>Security</option>[/B]
													</select>

																										<input type=hidden name=direction value="">
<input type=hidden name="pass" value="check">
<input type="hidden" name="nointern" value="1">
<input type="hidden" name="lang" value="en">
<input type="hidden" name="mode" value="">
<input type="hidden" name="target" value="">
<input type="hidden" name="subtarget" value="">
<input type="hidden" name="user_origin" value="">
<input type="hidden" name="title" value="">
<input type="hidden" name="fwd_nr" value="">

	<input type="hidden" name="dept" value="">
	<input type="hidden" name="dept_nr" value="">
	<input type="hidden" name="retpath" value="">
	<input type="hidden" name="edit" value="">
	<input type="hidden" name="pmonth" value="">
	<input type="hidden" name="pyear" value="">
	<input type="hidden" name="pday" value="">
	<input type="hidden" name="station" value="">
	<input type="hidden" name="ward_nr" value="">

	<input type="hidden" name="ipath" value="">

													</nobr><p>
													<INPUT type="image" src="images/en_login.gif" border=0 width="76" height="21">&nbsp;&nbsp;&nbsp;&nbsp;<a href="../../main/startframe.php?ntid=false&lang=en"><img src="images/en_cancel.gif" border=0 width="76" height="21"></a>
												</form>

											</td>
										</tr>
									</table>
								</td>

							</tr>
						</table>
					</td>
				</tr>
			</table>

			<p><br>
			</center>

		</td>

		<td class="passborder">&nbsp;
			
			</td>
	</tr>

	<tr >
		<td class="passborder" colspan=3>&nbsp;</td>
	</tr>

</table>
Member Avatar for diafol

This is what I was hoping you wouldn't be doing. As for the hidden fields these are probably irrelevant.

You don't need an user to stipulate their position. This should be done automatically from your users' mysql table. This is not the way to do it.

Just like [stoopkid] said, You need an extra filed in your database called 'type' or anything you want to call it.

Now wnhen the user log in, mysql will do a while loop and select what the user selected when signing up. You need to create different navigation for each user and use an if statement to compare the value in the filed [type] and decide which navigation to show the user.Its that simple,you are thinking to high .

Ok, take a look at this form,it may give you an idea as to what to do:

<form name="myForm" enctype="multipart/form-data" action="signup.php?nav=uss" onsubmit="return validateForm()" method="post">
		
         <table width="100%" border="0" bgcolor="#F4F4F4" cellspacing="1" cellpadding="1">
                          <tr>
                            <td height="30" colspan="4" align="left" bgcolor="#E4DDD7"><table width="100%" border="0" align="right" cellpadding="1" cellspacing="3">
                            <tr>
                               <td width="64%" height="25"><font class="mainlinks"><span class="style2">Member Registration Page:</span></font></td>
                          <td width="36%"><font color="#666666" class="mainlinks">&nbsp;&nbsp;&nbsp;</font><font class="mainlinks"><span class="style2" style="border-bottom-style:dotted" ><a href='loginlin.php'>Already a Member? Click here</a></span></font></td>
                                </tr>
                            </table></td>
                          </tr>
                          <tr>
                            <td colspan="2">&nbsp;</td>
                            <td width="69%">&nbsp;</td>
                          </tr>
                          <tr>
                            <td width="13%" align="left">&nbsp;</td>
                            <td width="18%" align="left"><font color="#666666" class="bodytxt">Frist Name <strong>:&nbsp;</strong></font></td>
                            <td align="left"><input name="fmane" type="text" class="bodytxt" id="fmane" size="35" /></td>
                          </tr>
                          <tr>
                            <td align="left">&nbsp;</td>
                            <td align="left"><font color="#666666" class="bodytxt">Last Name <strong>:</strong>&nbsp;</font></td>
                            <td align="left"><input name="lname" type="text" class="bodytxt" id="lname" size="35" /></td>
                          </tr>
                          <tr>
                            <td align="left">&nbsp;</td>
                            <td align="left"><font color="#666666" class="bodytxt">User Name <strong>:&nbsp;</strong></font></td>
                            <td align="left"><table width="100%" border="0" cellspacing="1" cellpadding="1">
							  <tr>
								<td><input name="username" type="text" class="bodytxt" id="username"  size="35" /></td>
								<td align="left"><div id="status"></div></td>
							  </tr>
							</table>							</td>
                          </tr>
                          <tr>
                            <td align="left">&nbsp;</td>
                            <td align="left"><font color="#666666" class="bodytxt">Password<strong> :</strong>&nbsp;</font></td>
                            <td align="left">
							<table width="100%" border="0" cellspacing="1" cellpadding="1">
							  <tr>
								<td><input name="password" sha1("password"); type="password" class="bodytxt" size="35" /></td>
								<td align="left"><div id="status"></div></td>
							  </tr>
							</table>							</td>
                          </tr>
						   <tr>
                            <td align="left">&nbsp;</td>
                            <td align="left"><font color="#666666" class="bodytxt">E-mail <strong>:</strong>&nbsp;</font></td>
                            <td align="left"><input name="email" type="email" class="bodytxt" size="50" />
                            <input name="free_access" type="hidden" value="free_access" size="30" />
                            </td>
                          </tr>
						  <tr>
                            <td align="left">&nbsp;</td>
                            <td align="left" class="bodytxt"><font color="#666666" class="bodytxt">Own a business ? <strong>:</strong>&nbsp;</font></td>
                            <td align="left">
                            
                            
                            
                          <div align='left' onClick='opendetails()' id='cont' class='bodyTxt'><b>Click here to
    continue</b></div>
    <div style='Display: none' id=details>
	<br />
	<div align='left' class='bodyTxt'><strong> -- Enter company name --</strong><br/>
    <input name="hotel" type="hotel" class="bodytxt" size="50" />
    </div>
	<br />
    
    <div>
                            
							</div>
                            </td>
                          </tr>
                          <tr>
                            <td align="left">&nbsp;</td>
                            <td align="left"><font color="#666666" class="bodytxt">Who are you? <strong>:</strong>&nbsp;</font></td>
                            <td align="left">
                            <select name="reg_acc" class="bodytxt" id="reg_acc" autocomplete="off">
                              <option value="-1">-- Select --</option>
                              <option value="1">Job Seeker</option>
                              <option value="2">Employer</option>
                              <option value="3">Restaurant</option>
                              <option value="Others">Others</option>
                            </select>
                            </td>
                          </tr>
                          <tr>
                            <td align="left">&nbsp;</td>
                            <td align="left"><font color="#666666" class="bodytxt">Country <strong>:&nbsp;</strong></font></td>
                            <td align="left"><select id="country" name="country" class=bodytxt>
                              <option>--Select Country--</option>
                                <?
																		$country_result = mysql_QUERY("select * from country order by country");  //select query
																		$country_num = mysql_numrows($country_result);
																		$a = 0;
																		while($a < $country_num) 
																		{
																			$country_id = mysql_result($country_result,$a,"id");
																			$country= mysql_result($country_result,$a,"country");
																			echo"<option value='$country'>$country</option>";
																			$a++;	
																	    }	
																	  ?>
                              </select></td>
                          </tr>
                          <tr>
                            <td height="5" align="left">&nbsp;</td>
                            <td height="5" align="left"><font color="#666666" class="bodytxt">I am <strong>:</strong>&nbsp;</font></td>
                            <td align="left" height="5">
                            <select name="gender" class="bodytxt" id="select">
                              <option selected>--Select Gender--</option>
                              <option>Male</option>
                              <option>Female</option>
                            </select>
                            </td>
                          </tr>
                          <tr>
                            <td align="left">&nbsp;</td>
                            <td align="left"><font color="#666666" class="bodytxt">Date of Brith<strong> :&nbsp;</strong></font></td>
                            <td align="left"><table width="45%" border="0" align="left" cellpadding="0" cellspacing="1">
                              <tr>
                                <td align="center">
                                <select name="birthday_day" class="bodytxt" id="birthday_day" autocomplete="off">
                                <option value="-1">Day</option>
                                <option value="1">1</option>
                                <option value="2">2</option>
                                <option value="3">3</option>
                                <option value="4">4</option>
                                <option value="2">2</option>
                                <option value="3">3</option>
                                <option value="4">4</option>
                                <option value="5">5</option>
                                <option value="6">6</option>
                                <option value="7">7</option>
                                <option value="8">8</option>
                                <option value="9">9</option>
                                <option value="10">10</option>
                                
                                <option value="11">11</option>
                                <option value="12">12</option>
                                <option value="13">13</option>
                                <option value="14">14</option>
                                <option value="15">15</option>
                                <option value="16">16</option>
                                <option value="17">17</option>
                                <option value="18">18</option>
                                <option value="19">19</option>
                                
                                <option value="20">20</option>
                                <option value="21">21</option>
                                <option value="22">22</option>
                                <option value="23">23</option>
                                <option value="24">24</option>
                                <option value="25">25</option>
                                <option value="26">26</option>
                                <option value="27">27</option>
                                <option value="28">28</option>
                                
                                <option value="29">29</option>
                                <option value="30">30</option>
                                <option value="31">31</option>
                                </select></td>
                                <td align="center">
                                <select class="bodytxt" id="birthday_month" name="birthday_month" autocomplete="off">
                                <option value="-1">Month</option>
                                <option value="1">January</option>
                                <option value="2">February</option>
                                <option value="3">March</option>
                                <option value="4">April</option>
                                <option value="5">May</option>
                                <option value="6">June</option>
                                <option value="7">July</option>
                                <option value="8">August</option>
                                <option value="9">September</option>
                                <option value="10">October</option>
                                <option value="11">November</option>
                                <option value="12">December</option>
								</select></td>
                                <td align="center">
                                <select name="myear" id="myear" class="bodytxt">
                                <option>Year</option>
                                <option>
                                    <?php
                              $count=1960;
                              do
                              echo "<option>$count</option>"."<br/>";
                              
                              while (++$count <= 2050)
                              ?>
                                </option>
                                </select>    </td>
                                </tr>
                            </table></td>
                          </tr>
                          <tr>
                            <td align="left">&nbsp;</td>
                            <td align="left">&nbsp;</td>
                            <td align="left">&nbsp;</td>
                          </tr>
                          <tr>
                            <td colspan="2" align="left">&nbsp;</td>
                            <td align="left">&nbsp;</td>
                          </tr>
                          <tr>
                            <td colspan="2">&nbsp;</td>
                            <td align="left">&nbsp;</td>
                          </tr>
                          <tr>
                            <td colspan="2">&nbsp;</td>
                            <td align="left"><input name="submit" type="submit" class="bg" id="button"  value="SignUp" onClick="validateForm(document.myForm)" />
                            <input name="reset" type="reset" class="bg" id="reset" value="Reset" /></td>
                          </tr>
                        </table>
                </form>

Mysql will do the work for you automatically and not yourself.

$sql="SELECT * FROM $tbl_name WHERE username='$username' and password='$password'";
 
$result=mysql_query($sql);
$qry_num = 0;
$qry_result = mysql_QUERY($sql); //select query\
$qry_num = mysql_numrows($qry_result);
$i = 0;
 
while($i < $qry_num)
 
{
$_SESSION['myid'] = mysql_result($qry_result,$i,"id");
$i++;
}
 
 
 
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $username and $password, table row must be 1 row
 
if($count==1)
commented: Thanks Man u are genius +1
<?php
include('config.php');
session_start();
$user_check=$_SESSION['login_user'];

$ses_sql=mysql_query("select username from admin where username='$user_check' ");

$row=mysql_fetch_array($ses_sql);

$login_session=$row['username'];

if(!isset($login_session))
{
header("Location: login.php");
}
?>

what are you doing any way?

Use titles that will benefit others when they search in daniweb and the web

are you trying to prevent users from geting to your cms ontil they login?

Thanks a lot, Ok let me tell you exactly what I need. Am designing a site for a small Health care center in my community. Now I want to use the same lo gin page for the Doctor(s), Nurse(s), Cashier(s} etc. and if login is successful they should be directed to the different page according to thier type. from protecting the pages from each other but Doctor(s) can access all pages.


The Form again:

<form>
Username:<input type="text" name="username" /><br />
Password:<input type="text" name="password" /><br />
<input type="submit" value="username" /><br />
</form>
Member Avatar for diafol

This is where you need a 'usertype' field in the users table.
You can use a relational model here to link it to a 'usertypes' table:

FOR EXAMPLE

users
user_id (int/autonumber) primary key
username (varchar/20)
password (varchar/32)
usertype_id (int) foreign key

usertypes
usertype_id (int/autonumber) primary key
usertype_label (varchar/20)

SO when an user logs in:

$res = mysql_query("SELECT * FROM users WHERE username = '$user' LIMIT 1");
if(mysql_num_rows($res)>0){
   $d = mysql_fetch_array($res)){
      if($pass == $d['password']){
         session_regenerate_id(); //security for changing permissions
         $_SESSION['user_id'] = $d['user_id'];
         $_SESSION['usertype_id'] = $d['usertype_id'];
         switch($d['usertype_id']){
            case 1:
               $loc = "nurse.php";
               break;
            case 2:
               $loc = "paramedic.php";
               break;
            case 3:
               $loc = "doctor.php";
               break;
            case 4:
               $loc = "medprac.php";
               break;
            case 5:
               $loc = "wardboss.php";
               break;
            case 6:
               $loc = "consultant.php";
               break;
         }
         header("Location: $loc");
      }
   }
}

Now all users have a unique homepage. You could have the switch routine in a function, so that you could refer to it in every page as part of an include file.

Every page that you have can now check the user's usertype_id (session) to see if they are allowed to be there. If not 'header' them away to their homepage.

E.g.

session_start();
if(isset($_SESSION['usertype_id']){
   //PAGE ALLOWED FOR NURSES AND DOCTORS ONLY
   if($_SESSION['usertype_id'] == 1 || $_SESSION['usertype_id'] == 3){
      //OK
   }else{
      //run switch routine (like I said - easier calling a function)
   } 
}else{
   header("Location: index.php");
}

I think this will work just fine for you,just create the 'usertype' field in your db,from what i see here,if am correct, you are to assign the #s 1 to 6 to each user when they singe up for the very first time.

Now, any time they login, your

$_session['']

function will compare the value they were assign when they signup to what is in your db and show them a home page you have assigned to them.

eg. of signup from below:

<form>
    Username:<input type="text" name="username" /><br />
    Password:<input type="text" name="password" /><br />
    Select User Type
    <select>
     <option value="1">nurse</option>
     <option value="2">paramedic</option>
     <option value="3">doctor</option>
     <option value="4">medprac</option>
     <option value="5">wardboss</option>
     <option value="6">consultant</option>
    </select>
    <input type="submit" value="username" /><br />
    </form>

Note: All of these values will be stored in your user table in your db.

I would add password='$password'

$res = mysql_query("SELECT * FROM users WHERE username = '$user' AND password = '$password' LIMIT 1");

just for more security.

Just follow ardav's example and you will be fine.

Parse error: syntax error, unexpected ')' in D:\wamp\www\Hospital CMS\h_cms\login_2.php on line 9

Code

<?php
include('../includes.config.php');
?>
<?php
$user=$_POST;
$password=$_POST;
$res = mysql_query("SELECT * FROM users WHERE username = '$user' LIMIT 1");
if(mysql_num_rows($res)>0){
$d = mysql_fetch_array($res)){
if($pass == $d){
session_regenerate_id(); //security for changing permissions
$_SESSION = $d;
$_SESSION = $d;
switch($d){
case 1:
$loc = "nurse.php";
break;
case 2:
$loc = "paramedic.php";
break;
case 3:
$loc = "doctor.php";
break;
case 4:
$loc = "medprac.php";
break;
case 5:
$loc = "wardboss.php";
break;
case 6:
$loc = "consultant.php";
break;
}
header("Location: $loc");
}
}
}
?>
Member Avatar for diafol

On line 9 just take off the extra ) on $res))

Still giving too many errors.

Member Avatar for diafol

Well, are you going to keep us guessing? What are they?

The code is untested as it depends on a hypothetical DB. It won't be majorly wrong, but there may be a few typos. So if you want more help, try being a bit more forthcoming with the exact nature of the error(s).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.