我有一点问题,请相信你们中的一位专家可以提供帮助:-p。
我在数据库中有以下表:
b_admins:
id
username
password
email
locationid
b_locations
id
name
description
登录脚本:
<?php
// Inialize session
session_start();
// Connection to MySQL Database.
include ('_includes/_dbconnection.php');
include ('_includes/_dbopen.php');
// Retrieve username and password from database according to user's input
$login = mysql_query("SELECT * FROM b_admins WHERE (ausername = '" . mysql_real_escape_string($_POST['username']) . "') and (apassword = '" . mysql_real_escape_string($_POST['password']) . "')");
// Check username and password match
if (mysql_num_rows($login) == 1) {
// Set username session variable
$_SESSION['username'] = $_POST['username'];
// Set locationid session varaible //// Modified 12 April 2012.
$_SESSION['locationid'] = $row_Recordset1["locationid"];
$locationid = $_SESSION['locationid'];
// Jump to secured page
header('Location: _home.php');
}
else {
// Jump to login page
header('Location: index.php');
}
// Script Source: http://frozenade.wordpress.com/2007/11/24/how-to-create-login-page-in-php-and-mysql-with-session/
?>
我的主页脚本:
// Check, if user is already login, if login proceed to _home.php
if (isset($_SESSION['username'])) {
header('Location: _home.php');
}
// Load Header file.
include ('_includes/_header.php');
// Template Construction.
// Create Homepage Layout after $home01.
$home01 = '<div id="imglogo"></div>
<div id="container">
<div class="top">
<div id="logo">
</div>
<ul class="socialicons">
</ul>
</div>
<div id="content" >
<div id="home">
<div class="latest">';
// MySQL Load Location Name from MySQL database after $home02.
$home02 = '<h3>';
// Create Notification Area for the Administrator after $home03.
$home03 = ' Administrator Panel</h3><p>You are logged in to make changes to your Branch, only your Branch details can be changed within this Administration Panel. You may proceed to make any changes using the menu at the bottom.</p></div>
<!-- /Latest section -->
<!-- News info section -->
<ul class="news-info">
<li><label>Users Registered</label>';
//MySQL Load User count from MySQL database after $home04.
$home04 = '<span>';
// Close Template.
$home05 = '</span></li>
</ul>
<!-- /News info section -->
</div>
<!-- /Home -->
<!-- Menu -->
<div class="menu">
<ul class="tabs">
<li><a href="_home.php" class="tab-home"></a></li>
<li><a href="_events.php" class="tab-events"></a></li>
<li><a href="_gallery.php" class="tab-portfolio"></a></li>
<li><a href="_template_edit.php" class="tab-contact"></a></li>
</ul>
</div>
</div>';
////////////////////////////////////////////////////////////////////////// Combining Template with MySQL Data.
/// Build Home Page from MySQL database.
$SQL = "SELECT * FROM b_admins, b_locations WHERE locationid ='$locationid' LIMIT 0, 1";
$result = mysql_query($SQL);
while ($db_field = mysql_fetch_assoc($result)) {
echo $home01;
echo $home02;
print $db_field['lcity'];
echo $home03;
}
/// Build Home Page News Section from MySQL database.
echo $home04;
$SQL = "SELECT count( * ) as total_record FROM `b_users` WHERE locationid = '$locationid'";
echo $home05;
/// Load Footer and Database close file.
include ('_includes/_footer.php');
include ('_includes/_dbclose.php');
?>
我想从 b_admins 中保存值“locationsid”,以便能够使用 SQL 从数据库中检索数据,其中“locationsid”与数据库 b_locations 中的表相同。
我还收到以下错误,我不知道如何通过登录脚本登录时修复:“ http://localhost/xxxxx/_home.php上的网页导致重定向过多。”
提前致谢 :-)