在我尝试登录时,在此登录页面上会显示一个空白页面。虽然登录成功,但点击个人资料标签时,dashboard.php
可见。此外,整个过程在我的WAMP服务器中运行良好。
导致此问题的原因是什么?
<?php
ob_start();
$host="localhost"; // Host name
$username="######"; // Mysql username
$password="######"; // Mysql password
$db_name="devspan_Users"; // Database name
$tbl_name="Members"; // Table name
// Connect to server and select databse.
$con=mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_query("CREATE DATABASE IF NOT EXISTS ".$db_name);
mysql_select_db("$db_name",$con)or die("cannot select DB");
if(mysql_num_rows(mysql_query("SHOW TABLES LIKE '".$tbl_name."'",$con))==0)
{
$sql="CREATE TABLE Members(
id int(4) NOT NULL auto_increment,
username varchar(65) NOT NULL default '',
password varchar(65) NOT NULL default '',
PRIMARY KEY (`id`)
)";
mysql_query($sql,$con);
}
// Define $myusername and $mypassword
$myusername=$_POST['username'];
$mypassword=$_POST['password'];
// To protect MySQL injection
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql,$con);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword
if($count==1){
// Register
session_start();
$_SESSION["myusername"]=$myusername;
$_SESSION["mypassword"]=$mypassword;
header("location:dashboard.php");
}
else {
echo "Wrong Username or Password";
}
ob_end_flush();
?>
答案 0 :(得分:0)
在这段代码中:
// If result matched $myusername and $mypassword
if($count==1){
// Register
session_start();
$_SESSION["myusername"]=$myusername;
$_SESSION["mypassword"]=$mypassword;
header("location:dashboard.php");
}
else {
echo "Wrong Username or Password";
}
ob_end_flush();
?>'
最后?>'
是什么?只需删除那个&amp;再试一次。另外,请注意我将header
行更改为header('Location: dashboard.php');
清理的一部分,此处将其清理。
ob_start();
$host="localhost"; // Host name
$username="######"; // Mysql username
$password="######"; // Mysql password
$db_name="devspan_Users"; // Database name
$tbl_name="Members"; // Table name
// Connect to server and select databse.
$con=mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_query("CREATE DATABASE IF NOT EXISTS " . $db_name);
mysql_select_db("$db_name", $con) or die("cannot select DB");
if (mysql_num_rows(mysql_query("SHOW TABLES LIKE '" . $tbl_name . "'",$con))= = 0) {
$sql = "CREATE TABLE"
. " Members(id int(4) NOT NULL auto_increment,"
. " username varchar(65) NOT NULL default '',"
. " password varchar(65) NOT NULL default '',"
. " PRIMARY KEY (`id`)"
. ")"
;
mysql_query($sql,$con);
}
// Define $myusername and $mypassword
$myusername=$_POST['username'];
$mypassword=$_POST['password'];
// To protect MySQL injection
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql = "SELECT *"
. " FROM $tbl_name"
. " WHERE"
. " username='" . $myusername . "'"
. " AND password='" . $mypassword . "'"
;
$result = mysql_query($sql, $con);
// Mysql_num_row is counting table row
$count = mysql_num_rows($result);
// If result matched $myusername and $mypassword
if ($count == 1){
// Register
session_start();
$_SESSION["myusername"] = $myusername;
$_SESSION["my password"] = $mypassword;
header('Location: dashboard.php');
}
else {
echo "Wrong Username or Password";
}
ob_end_flush();
答案 1 :(得分:0)
更新:问题在于我的托管而不是我的代码。 sql查询花了一生的时间来获取数据,因此页面没有加载。解决方案:更改了我的托管服务。