0

Hi, can anyone help plz? I want to fetch data from database and show in multiple check box value e.g Registration Num of student in 5 checkboxes with different values but really dont get how to do this :( plz anyone provide me easy code in php i will be really thankful

2
Contributors
5
Replies
11
Views
5 Years
Discussion Span
Last Post by pzuurveen
0

show us the code you have so fare

I have solved my problem.. thanx for the concern... but one more thing if u can help... I have three users in my university registration system.. Teacher, Student and admin.. now m selecting their UserType from User table and match their ID and Password.. but m not able to maintain the sessions of all them.. :( actually m beginner in learning php here is my code if u help me i will be thakful

[B]Login.html file
[/B]
<form name="form1" method="post" action="UsersLogin.php">
             <p class="clearfix">
                <label for="usertype">Usertype  &nbsp;&nbsp; &nbsp;</label>
                <select name="user">
          <option value="Admin" selected="selected">Admin</option>
          <option value="Teacher">Teacher</option>
          <option value= "Student">Student</option>
        </select>
          </p>
              <p class="clearfix">
                <label for="email">Email &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;</label>
                <input name="Email" id="email" type="text" value="" />
          </p>
          <p class="clearfix">
                <label for="password">Password&nbsp;&nbsp; &nbsp; </label>
                <input name="Password" id="email2" type="password" value="" />
          </p>
          <p class="clearfix">&nbsp;</p>
          <p class="clearfix check">
            <label for="remember" id="remlabel"></label>
            <input name="submit" id="submit" type="submit" value="" />
          </p>
            </form>

UsersLogin.php file

<?php
//session_start();

if(isset($_POST['submit']))
{
    print_r($_REQUEST);
	echo $Email = $_POST['Email'];
	echo $Password = $_POST['Password'];
	echo $UserType= $_POST['user'];
	echo $count=0;

	
	if($Email == "" || $Password == "")
	{
		echo "Either email or password field is empty.";
		echo "<br/>";
		echo "<a href='login.php'>Go back</a>";
	}
	else{
	
	if($UserType=='Teacher')
	{


	mysql_connect("localhost", "root" , "") or die ('Error:' . mysql_error());
	
    mysql_select_db("university_registration");
	
	echo $result = mysql_query("select * from user where Email='$Email' and Password='$Password'")
		or die("Could not execute the select query.");

		 $row = mysql_fetch_assoc($result);
		
		if(is_array($row) && !empty($row))
		{
			/*$_SESSION['valid'] = $row['Email'];
			$_SESSION['pass']  = $row['Password'];
			$_SESSION['type']  = $_row['UserType'];
*/
			echo $count= 1; //for teacher	
				header('Location: TeacherProfile.php');
	    }
		else
		{
			echo "Invalid email or password.";
			echo "<br/>";
			echo "<a href='login.php'>Go back</a>";
		}
		 /* if(isset($_SESSION['valid']) && $count ==1)
		{
			echo "Welcome ".$_SESSION['valid']."!";
			echo "<br/>";
		
		}*/
		
	//	header('Location: TeacherProfile.php');
		
			/*}	
			else{
			 "Invalid email or password.";
			echo "<br/>";
			echo "<a href='login.php'>Go back</a>";
			}*/
		}
	  if($UserType=='Student')
	{


	mysql_connect("localhost", "root" , "") or die ('Error:' . mysql_error());
	
    mysql_select_db("university_registration");
	
	echo $result = mysql_query("select * from user where Email='$Email' and Password='$Password'")
		or die("Could not execute the select query.");
		
		$row = mysql_fetch_assoc($result);
		
		if(is_array($row) && !empty($row))
		{
			/*$_SESSION['valid'] = $row['Email'];
			$_SESSION['pass']  = $row['Password'];
			$_SESSION['type']  = $_row['UserType'];
*/
			echo $count= 2; //for teacher	
				header('Location: StudentProfile.php');
	    }
		else
		{
			echo "Invalid email or password.";
			echo "<br/>";
			echo "<a href='login.php'>Go back</a>";
		}
		
	}
		 if($UserType=='Admin')
	{


	mysql_connect("localhost", "root" , "") or die ('Error:' . mysql_error());
	
    mysql_select_db("university_registration");
	
	echo $result = mysql_query("select * from user where Email='$Email' and Password='$Password'")
		or die("Could not execute the select query.");
		
		$row = mysql_fetch_assoc($result);
		
		if(is_array($row) && !empty($row))
		{
			/*$_SESSION['valid'] = $row['Email'];
			$_SESSION['pass']  = $row['Password'];
			$_SESSION['type']  = $_row['UserType'];
*/
			echo $count= 3; //for teacher	
				header('Location: AdminProfile.php');
	    }
		else
		{
			echo "Invalid email or password.";
			echo "<br/>";
			echo "<a href='login.php'>Go back</a>";
		}
		
	}

		/*if(isset($_SESSION['Email']) && $count ==3)
		{
		 echo "Welcome ".$_SESSION['Email']."!";
			echo "<br/>";
			header('Location: AdminProfile.php');
		}*/
		/*else if(isset($_SESSION['valid']) && $count ==3)
		{
			echo "Welcome ".$_SESSION['valid']."!";
			echo "<br/>";
			header('Location: AdminProfile.php');

		}*/
	//}
//	}
	
	}

	}
?>
0

You should put usertype into your db.
Have your users login with just an email and a password
Then do a query on youre db to check email&password and get the usertype

0

Yes, i have usertype feild in my database.. here is not the problem of comparing user type with their email and password.. its working... my sessions are not creating when it redirects to the profile page of any member ... i want if u provide me session code for this scenario m tired of doing this :(

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.