我正在构建一个基于 PHP 的登录/创建帐户脚本。只要文件顶部的 PHP 被注释掉/不存在,表单就会正确显示。一旦我将 php 放入文件中,表单就会消失。谁能看看他们是否找到了为什么会发生这种情况的原因?
谢谢,马特
//edit 所以我发现错误在于用于检查密码匹配的 if/else 语句。如果我注释掉 else 语句,页面会正确显示,一旦注释掉,我就会得到一个空白页面。我什至注释掉了 mysql_query() 并且只是输入了一个简单的回声,没有运气。
$db_found2 = conServer();
if($db_found2) {
if (!empty($_POST['username']) || !empty($_POST['password']) || !empty($_POST['email']) || !empty($_POST['conpassword'])) {
$username = $_POST['username'];
$password = $_POST['username'];
$conpassword = $_POST['conpassword'];
$email = $_POST['email'];
if ($password != $conpassword) {
$errormsg = "";
$passerr = "Passwords do not match!";
}
}
}
function conServer() {
$user_name = ""; //not displayed for privacy purposes
$password = ""; //not displayed for privacy purposes
$database = ""; //not displayed for privacy purposes
$server = "localhost";
$table = "users";
$db_handle = mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database, $db_handle);
return $db_found;
}
?>
<html>
<head>
<link rel=stylesheet href="login.css" />
</head>
<body class="login">
<div id="login">
<form id="loginform" action="create.php" method="post">
<p>
<label for="username">
Username *
<br>
<input type="text" name="username" id="username"/><span class="error"><?php echo $errormsg; ?></span>
</label>
</p>
<p>
<label for="password">
Password *
<br>
<input type="password" name="password" id="password"/><span class="error"><?php echo $errormsg; ?></span>
</label>
</p>
<p>
<label for="password">
Confirm Password *
<br>
<input type="password" name="conpassword" id="password"/><span class="error"><?php echo $errormsg; ?></span><span class="error"><?php echo $passerr; ?></span>
</label>
</p>
<p>
<label for="email">
Email *
<br>
<input type="text" name="email" id="email" /><span class="error"><?php echo $errormsg; ?></span>
</label>
</p>
<input type="submit" id="submit" value="Go ->"/>
</form>
</div>
</body>
</html>