很抱歉这个不太有用的头衔。。我不知道该如何简洁地描述它。
查询
<?php
// Parse the log in form if the user has filled it out and pressed "Log In"
if (isset($_POST["username"]) && isset($_POST["password"])) {
$username = $_POST["username"]; // filter everything but numbers and letters
$password = $_POST["password"]; // filter everything but numbers and letters
// Connect to the MySQL database
include "dbconnect.php";
$sql = mysql_query("SELECT username, admin FROM logins WHERE username='$username' AND password='$password' LIMIT 1"); // query the person
// ------- MAKE SURE PERSON EXISTS IN DATABASE ---------
$existCount = mysql_num_rows($sql); // count the row nums
if ($existCount == 1) { // evaluate the count
while($row = mysql_fetch_array($sql)){
$username = $row["username"];
$admin = $row["admin"];
}
if ($admin ==2) {
$coach = $_POST["username"]; // filter everything but numbers and letters
$password = $_POST["password"]; // filter everything but numbers and letters
$sql = mysql_query("SELECT id, activity FROM coaches WHERE username='$coach' AND password='$password' LIMIT 1");
while($row = mysql_fetch_array($sql)){
$id = $row["id"];
$activity = $row["activity"];
}
$_SESSION["id"] = $id;
$_SESSION["coach"] = $coach;
$_SESSION["password"] = $password;
$_SESSION["activity"] = $activity;
header("location: coach-home.php");
exit();
}
else
if ($admin ==1)
{ header("location: player-login.php"); }
exit();
} else {
echo 'That information is incorrect, try again <a href="testlog.php">Click Here $username</a>';
exit();
}
}
?>
为了帮助节省时间,在我开始在(admin==2){}位中输入查询之前,一切都正常工作。我试图让它获取已经发送的登录详细信息,然后,一旦注意到他们的管理员级别(在本例中,2=他们是管理员),它将运行另一个查询来为管理员创建会话,并将他们带到Coach主页。
然而,似乎正在发生的事情是没有创建会话(duh),因为coach home没有看到有效的会话,因此会重定向我。
我想知道的是a。如果我想做的事情是可能的,并且失败了b。我开始研究重定向。。。因此,在(admin==2)之后,它会将用户引导到coach login,其中有与上面基本相同的查询,然后将其重定向到coach home。但是,页面并没有这样做,而是在coach login时显示为空(下面是coach-login.php代码)
页面底部的表格(如果相关?)
<form id="form1" name="form1" method="post" action="testlog.php">
User Name:<br />
<input name="username" type="text" id="username" size="40" />
<br /><br />
Password:<br />
<input name="password" type="password" id="password" size="40" />
<br />
<br />
<br />
<input type="submit" name="button" id="button" value="Log In" />
</form>
任何帮助都将不胜感激。
coach-login.php
<?php
// Parse the log in form if the user has filled it out and pressed "Log In"
if (isset($_POST["username"]) && isset($_POST["password"])) {
$coach = $_POST["username"]; // filter everything but numbers and letters
$password = $_POST["password"]; // filter everything but numbers and letters
// Connect to the MySQL database
include "dbconnect.php";
$sql = mysql_query("SELECT id, activity FROM coaches WHERE username='$coach' AND password='$password' LIMIT 1"); // query the person
// ------- MAKE SURE PERSON EXISTS IN DATABASE ---------
$existCount = mysql_num_rows($sql); // count the row nums
if ($existCount == 1) { // evaluate the count
while($row = mysql_fetch_array($sql)){
$id = $row["id"];
$activity = $row["activity"];
}
$_SESSION["id"] = $id;
$_SESSION["coach"] = $coach;
$_SESSION["password"] = $password;
$_SESSION["activity"] = $activity;
header("location: coach-home.php");
exit();
} else {
echo 'That information is incorrect, try again <a href="index.php">Click Here</a>';
exit();
}
}
?>
最佳答案
是的,除了coach login.php之外,我在大多数文件中都有session_start();
根据OP的愿望:session_start();
也必须在“coach login.php”中,因为其中有会话变量。
如前所述,session_start();
必须在所有使用会话的文件中。
这就是为什么会议没有继续下去。