Jump to content

[SOLVED] guys i nid help.. im a php beginner..


Recommended Posts

<?php
$time = time() + 3600; 
setcookie("ID",$_POST['id'], $time); 
setcookie("pass",$_POST['password'], $time); 
			?>
<html>

<head>
<link href="interface design/css.css" rel="stylesheet" type="text/css"></head>
<body>
<?php
#connect to MySQL Server
@mysql_pconnect('localhost', 'root', 'tmc') or die(mysql_error());

#connect to database

@mysql_select_db('tgp') or die(mysql_error());

// if form has been submitted

// makes sure they filled it in
	if(!$_POST['id'] | !$_POST['password']) 
	{?>
	<p class="error">Login Failed!<br>Please Type your Username and Password agian!</p>
	<?php
	}
// checks it against the database

$query = mysql_query("SELECT * FROM member WHERE Cid = '".$_POST['id']."'")or die(mysql_error());
$query2 = mysql_query("SELECT * FROM member WHERE staffID = '".$_POST['id']."'")or die(mysql_error());
$separator = $query, $query2;
//Gives error if user dosen't exist
$row = mysql_num_rows($query);
$row2 = mysql_num_rows($query2);
	if ($row == 0) 
	{?>
	<p class="error">Unauthorized Personnel</p>
	<?}
	and if ($row2 == 0) 
	{?>
	<p class="error">Unauthorized Personnel</p>
	<?}
if($separator == $query)
{	

	while($list = mysql_fetch_array( $query )) 
	{

//gives error if the password is wrong
		if ($_POST['password'] != $list['password']) 
		{?>

			<script>window.location ="login2.html"</script>

		<?}

		else 
		{ 
				?>
				<script>
				window.location="interface design/member.php"
				</script>
				<?php

		}
	} 
}
else if ($separator == $query2)  {
	while($list = mysql_fetch_array( $query2 )) 
		{  if ($_POST['password'] != $list['password']) 
		{?>

			<script>window.location ="login2.html"</script>

		<?}
		else
		// if login is ok then we add a cookie 
			if ($list['userlvl'] == "admin"){

//testing where to go if correct
				?>
				<script>
				window.location="interface design/home.html"
				</script>
				<?php

		   }
		   else if($list['userlvl'] == "staff"){
			   ?>
                                      //this is just testing if correct where to go..
			   <script>window.location = "interface design/room.html";</script>
			   
			   <?}

		}

?>

ok heres the question... i created one login page form... to validate the login form i use php.. and i have two different tables a staff table and a member table.. both have id and password

then i want to check for the id if its from staff table or member table... im having a difficulty hir.. pls help me phpfreakers...

Link to comment
https://forums.phpfreaks.com/topic/71538-solved-guys-i-nid-help-im-a-php-beginner/
Share on other sites

You might want to rethink how the database itself is structured.  Staff are people, and members are people.  In general, you want one table to store info about people.  Just have a column in the table that tells you whether the person is a member or staff.  This way you only have to run one query, then check the value of a column to decide what action to take next.  This will also make it much easier to ensure that a staff and member don't choose the same login name.

First a question:

Why do you have 2 tables!

why not 1 table with a field for accesslevel (1-5)

1=admin

5=guess

sort of thing ?

 

if not try this

<?php
$Level = 0;
$ID = (int)$_POST['id'];
//i assume Cid & staffID are INT's (if their string change to ='$ID'"
$query = mysql_query("SELECT * FROM member WHERE Cid = $ID")or die(mysql_error());
$row = mysql_num_rows($query);  
$C = mysql_num_rows($query);
if($C >0)
{
$Level = 1;
}
$query = mysql_query("SELECT * FROM member WHERE staffID = $ID")or die(mysql_error());
$row = mysql_num_rows($query);  
$C = mysql_num_rows($query);
if($C >0)
{
$Level = 2;
}
switch($Level)
{
default:
case 0:
echo "No Access";
break;
case 1:
echo "Member";
break;
case 2:
echo "Staff";
break;


}
?>

This will also make it much easier to ensure that a staff and member don't choose the same login name.

Thats a perfect point..

EDIT: i'll admit i have created a System and used 2 extra tables for "extended info" and of different types but it makes management much harder, having to use JOINs to view the correct data and updates are a nightmare at times..

In our big database here at work, there are several tables like this, and they simply contain ALL columns that may be used on any type of record.

 

For example, one table stores both individuals and organizations.  An individual has a first, last and middle name, but an organization just has an organization name.  These are four different fields.  The fields that aren't needed for a particular record are simply left NULL.  Both approaches have their problems, and I'm not sure which one I prefer.

<?

$time = time() + 3600;

setcookie("ID",$_POST['id'], $time);

setcookie("pass",$_POST['password'], $time);

?>

<html>

 

<head>

<link href="interface design/css.css" rel="stylesheet" type="text/css"></head>

<body>

<?php

#connect to MySQL Server

@mysql_pconnect('localhost', 'root', 'tmc') or die(mysql_error());

 

#connect to database

 

@mysql_select_db('tgp') or die(mysql_error());

 

//if the login form is submitted

// if form has been submitted

 

// makes sure they filled it in

if(!$_POST['id'] | !$_POST['password'])

{?>

<p class="error">Login Failed!<br>Please Type your Username and Password agian!</p>

<?php}

// checks it against the database

 

$query = mysql_query("SELECT * FROM login WHERE id = '".$_POST['id']."'")or die(mysql_error());

 

//Gives error if user dosen't exist

$row = mysql_num_rows($query);

if ($row == 0)

{?>

<p class="error">Unauthorized Personnel</p>

<? print "fuck";}

while($list = mysql_fetch_array( $query ))

{

 

//gives error if the password is wrong

if ($_POST['password'] != $list['password'])

{?>

 

<script>window.location ="login2.html"</script>

 

<?}

 

else

{

 

 

 

if ($list['userlevel'] == "admin"){

 

 

?>

<script>

window.location="interface design/home.html"

</script>

<?php

 

  }

  else if($list['userlevel'] == "staff"){

  ?>

  <script>window.location = "interface design/room.html";</script>

 

  <?}

 

else if($list['userlevel'] == "user"){

  ?>

  <script>window.location = "interface design/member.php";</script>

 

  <?}

 

}

}

 

 

?>

 

ok now im workin wif one table.. its not workin... any suggestion guys.. i got 3 column in my login table id password and userlevel

Please use the code tag (#) button or [.code] [/.code] (no dot)

Not working, doesn't help.. what doesn't work?

 

what about a simple approach


<?php
$time = time() + 3600; 
setcookie("ID",$_POST['id'], $time); 
setcookie("pass",$_POST['password'], $time); 
?>
<html>
<head>
<link href="interface design/css.css" rel="stylesheet" type="text/css"></head>
<body>
<?php
#connect to MySQL Server
@mysql_pconnect('localhost', 'root', 'tmc') or die(mysql_error());

#connect to database
@mysql_select_db('tgp') or die(mysql_error());

//if the login form is submitted
// if form has been submitted

// makes sure they filled it in
if(isset($_POST['id']) && isset($_POST['password'])) 
{
// checks it against the database
//need to add a filter here
$pass = $_POST['password'];
$id = $_POST['id'];

$query = mysql_query("SELECT * FROM login WHERE id = '$id' AND password = '$pass'")or die(mysql_error());

//Gives error if user dosen't exist
$row = mysql_num_rows($query);
if ($row == 0) 
{
?>
	<p class="error">Unauthorized Personnel</p>
<?php	 print "Oppps";}
}else{
	$user = mysql_fetch_array( $query );
	echo "<script>";
	switch(strtolower($user['userlevel']))
	{
		default:
			$page = "login2.html";
		break;
		case "admin":
			$page = "interface design/home.html";
		break;
		case "staff":
			$page = "interface design/room.html";
		break;
		case "user":
			$page = "interface design/member.html";
		break;
	}
	echo "	window.location=\"$page\"";
	echo "</script>";
} 
}else{
?>
<p class="error">Login Failed!<br>Please Type your Username and Password agian!</p>
<?php
}


?>

 

//untested

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.