0

我目前正在为足球联赛建立一个系统。并且目前正在处理用于添加结果的脚本文件。大多数脚本都有效,结果总是成功添加到数据库中。但是,身份验证部分似乎失败了。第 12 行的 if 语句似乎没有触发,我不明白为什么。

我的代码可以在这里的 pastebin 链接中找到:http: //pastebin.com/ty4pdGgn

<?PHP

include 'functions.php';
dbConnect();

//$userEmail = mysql_real_escape_string($_POST["userEmailText"]);
$userCode = mysql_real_escape_string($_POST["userPasscodeText"]);

$authenticated = false;

$userEmail = "info@example.com";
if ($userEmail == "info@example.com") {
        header('Location: ../results.php?error=authentication');
}

$allUsers = mysql_query("SELECT * FROM accounts WHERE email = '$userEmail'");
while ($thisUser = mysql_fetch_assoc($allUsers)){
        if ($userCode != $thisUser['passCode']) {
                header('Location: ../results.php?error=authentication2');
        }
        echo $thisUser['passCode'];
        $authenticated = true;
        $userID = $thisUser['userID'];
}

if (!$authenticated) {
        header('Location: ../results.php?error=authentication3');
}

$dateSubmitted = $_POST['submissionDate'];
$homeTeam = $_POST['homeTeam'];
$awayTeam = $_POST['awayTeam'];
$homeGoals = $_POST['homeGoals'];
$awayGoals = $_POST['awayGoals'];

if ($homeTeam == $awayTeam) {
        header("Location: ../results.php?error=team");
}

if (getTeamLeague($homeTeam) != getTeamLeague($awayTeam)) {
        header("Location: ../results.php?error=league");
} else {
        $leagueID = getTeamLeague($homeTeam);
}

if ($homeGoals > $awayGoals) {
        $winnerID = $homeTeam;
} else if ($homeGoals < $awayGoals) {
        $winnerID = $awayTeam;
} else if ($homeGoals == $awayGoals) {
        $winnerID = -1;
}

$cQuery = mysql_query("INSERT INTO results VALUES ('', $userID, '$dateSubmitted', $leagueID, $homeTeam, $homeGoals, $awayTeam, $awayGoals, $winnerID, 0)");

if ($cQuery){
        header('Location: ../results.php');
} else {
                echo mysql_error();
}


?>

对此问题的任何帮助将不胜感激。functions.php 不包含任何错误,因为这与数据库条目有关,而不是身份验证。

4

2 回答 2

1

die();在后面放一个header("Location:...");

于 2013-09-04T22:58:18.317 回答
0

由于您粘贴的比较代码(第 12 行的“if”部分)必须有效,我有两个建议:

  1. 放一个 die(); 或退出();在 header() 部分之后。
  2. 试试看这里,因为我不确定 header() 是否有效,而您设置的位置路径是相对的。基本建议是始终使用基本路径进行重定向,例如“ http://your.site.com/script.php ”)。
于 2013-09-04T23:07:26.873 回答