dongpan1416 2013-09-04 22:45
浏览 48
已采纳

PHP如果语句没有被触发

I'm currently building a system for a football league. And are currently working on the script file for adding results. Most of the script works and the result is always successfully added to the database. However the authentication part seems to fail. The if statement on line 12 does not seem to fire and I can't understand why.

My code can be found in the pastebin link here: 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();
}


?>

Any help with this matter will be much appreciated. The functions.php contains no errors as this is all to do with database entry and not the authentication.

  • 写回答

2条回答 默认 最新

  • douzhongju8780 2013-09-04 22:58
    关注

    Put a die(); after the header("Location:...");

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?