login using 2 databases

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Smackie
Forum Contributor
Posts: 302
Joined: Sat Jan 29, 2005 2:33 pm

login using 2 databases

Post by Smackie »

Alrighty i have a friend that came to me and asked me if i could help him with his login script and i said sure but when i looked at the script the script is i think php5 i only been working with php4 but he is trying to use 2 databases in the script can someone help me here is the script

Code: Select all

<?

ob_start();
session_start();


include '../includes/admindb.php';
include '../includes/tf73db.php';

echo "<title>Administration Center</title>";
echo "<body bgcolor='#000000' text='#FFFF80'>";

//GNSF Header
echo " <p align='center'><table border='0'>";
echo "	<tr>";
echo "		<td align='center' valign='middle'><img src='../images/GVN2.gif'></td>";
echo "		<td align='center' valign='middle'><h1>Global Naval Strike Force<br>Administration Center</h1></td>";
echo "		<td align='center' valign='middle'><img src='../images/GVN2.gif'></td>";
echo "	</tr>";
echo " </table></p>";

$safe['callsign'] = mysql_real_escape_string($_POST['callsign']);
$safe['password'] = mysql_real_escape_string($_POST['password']);
$query_admin_user = "SELECT * FROM ADMINISTRATION.admin_user WHERE callsign = '{$safe[callsign]}'";
$result_admin_user = mysql_query($query_admin_user) or die("Query Failed: ".mysql_error());
while ($line = mysql_fetch_array($result_admin_user)) {
	$division = $line['task_force'];
	$type = $line['type'];
	$other = $line['other'];
	$deactive = $line['deactive'];
	if ($division == "TF-73") {
		$query_user = "SELECT rank FROM TF73SB.user WHERE callsign = '{$safe[callsign]}' AND password = MD5('{$safe[password]}')";
		$result_user = mysql_query($query_user) or die("Query Failed: ".mysql_error());
		while ($line = mysql_fetch_array($result_user)) {
			$rank = $line['rank'];
		}
	}
}
if ($deactive == 1) {
	echo "<p align='center'>Your Account Has Been Deactivated Due To The Number Of Failed Login Attempts. Please Contact The Web Department</p>";
} else {
	if(mysql_num_rows($result_user)) {
		$_SESSION['callsign'] = $_POST['callsign'];
		$_SESSION['password'] = $_POST['password'];
		$_SESSION['task_force'] = $division;
		$_SESSION['type'] = $type;
		$_SESSION['other'] = $other;
		if ($_SESSION['type'] == "1") {
			$division_array = array("ADMIN", "TF-73");
		} elseif ($_SESSION['task_force'] == "admin") {
			$division_array = array("ADMIN", "TF-73");
		} elseif ($_SESSION['task_force'] == "tf-73") {
			$division_array = array("TF-73");
		}
		$arrayLength = count($division_array);
		for ($i = 0; $i < $arrayLength; $i++) {
			$link_value = strtolower($division_array[$i]);
			if ($_SESSION['type'] == 4) {
				$link_value = $link_value.".php?action=32";
			} else {
				$link_value = $link_value.".php";
			}
			$divisions_links .= "<a href='admin-".$link_value."'>".$division_array[$i]."</a>";
			if ($i != $arrayLength-1) {
				$divisions_links .= " | ";
			}
		}
		$query_logger = "SELECT ip,logged FROM ADMINISTRATION.admin_user WHERE callsign='".$_SESSION['callsign']."'";
		$result_logged = mysql_query($query_logger) or die("Query Logged: ".mysql_error());
		while ($line = mysql_fetch_array($result_logged)) {
			$ip = $line['ip'];
			$logged = $line['logged'];
		}
		$today_is = date("Y-m-d H:i:s");
		$ip_is = getenv("REMOTE_ADDR");
		$query_update = "UPDATE ADMINISTRATION.admin_user
							SET
							ip = '$ip_is',
							logged = '$today_is'
							WHERE callsign = '".$_SESSION['callsign']."'";
		$result_update = mysql_query($query_update) or die("Query Failed: ".mysql_error());
		$_SESSION['divisions_links'] = $divisions_links;
		echo "<p align='center'>".$_SESSION['divisions_links']." | <a href='logout.php'>Log Out</a></p>";
		echo "<p align='center'>Welcome $rank ".ucwords($_SESSION['callsign'])."</p>";
		echo "<p align='center'>Today Is <b>$today_is</b> And The Last Time You Logged In Was <b>$logged</b>";
	} else {
		$error = $_POST['error_number'] + 1;
		if ($error == 3) {
			$today_is = date("Y-m-d H:i:s");
			$ip_is = getenv("REMOTE_ADDR");
			$query_deactivate = "UPDATE ADMINISTRATION.admin_user
									SET
									deactive = '1',
									fail_ip = '$ip_is',
									fail_dater = '$today_is'
									WHERE callsign = '".$_POST['callsign']."'";
			$result_deactivate = mysql_query($query_deactivate);
			echo "<p align='center'>You Have Tried 3 Times To Log In, Your Account Has Been Deactivated. Please Contact The Web Department</p>";
		} else {
			header("Location: index.php?error=$error");
		}
	}
}


?>
here is the error that keeps popin up
Query Failed: select command denied to user: 'user@localhost' for table 'user'
thank you
Smackie
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the error would suggest "user" doesn't have select rights granted to it in that database/table.
Post Reply