【发布时间】:2011-12-10 22:15:11
【问题描述】:
<?php
function redirect_to_index_with_error(){
echo '<meta http-equiv="refresh" content="0;url=index.php">';
}
function go_to_home(){
echo '<meta http-equiv="refresh" content="0;url=home.php">';
}
$email = mysql_real_escape_string($_POST['username']); echo $email;
$pwd = mysql_real_escape_string($_POST['password']);
echo $pwd;
$query = "SELECT * FROM users WHERE email='$email' AND password=MD5('$pwd')";
echo "query variable created.";
mysql_connect("localhost","root","") or die(mysql_error());
echo "connected."; //nothing
mysql_select_db("mcp") or die(mysql_error());
$results = mysql_query($query) or die(mysql_error());
if(mysql_num_rows($results) == 0){
redirect_to_index_with_error();
exit();
}
$userID = null;
$name = null;
$school = null;
$mod = null;
while($user = mysql_fetch_array($results)){
$userID = $user['ID'];
$name = $user['Name'];
$school = $user['School'];
if($user['Mod'] == '1')
$mod = true;
else
$mod = false;
}
if(!isset($_SESSION))
session_start();
//set session variables
$_SESSION["userID"] = $userID;
$_SESSION["name"] = $name;
$_SESSION["school"] = $school;
$_SESSION["mod?"] = $mod;
go_to_home();
exit();
?>
PHP 回显所有内容,直到“连接”为止。它甚至没有显示mysql错误。我已经让这段代码在带有 WAMP 的 Windows 上完美运行,但在带有 MAMP 的 Mac 上却没有。我已经验证服务器正在运行,所以我无法判断问题所在。我正在使用 PHP 5.3.6。
【问题讨论】:
-
如果一切顺利,它似乎不会输出任何东西,是吗?
-
对不起,我忘了发布整个代码。我现在就去做。
-
这段代码在“连接”后应该回显什么?
-
您是否验证并确保您要查找的用户确实存在?
-
是的,我检查了 phpMyAdmin。 shane 的回答解决了这个问题。