0
我正在处理朋友的项目,我负责设计一个简单的网站来与他的数据库进行交互。我写了下面的代码,他的一个页面:页面源显示我的页面部分不显示
<!DOCTYPE html>
<html>
<head>
<title>Narcissus-OTS</title>
<meta charset="utf-8" />
<!--<meta http-equiv="refresh" content="3;url=./account.php" />-->
</head>
<body>
<?php include("./common/database.php"); ?>
<?php
//Grabs user-submitted credentials from previous page
$accountid = mysql_escape_string($_POST["acc"]);
$password = mysql_escape_string($_POST["pass"]);
$confirmation = mysql_escape_string($_POST["passtwo"]);
//Insures there is no duplicate database entry for accountid
$querycheck = $db->query("
SELECT *
FROM accounts a
WHERE a.name = $accountid
");
$checkifone = $querycheck->rowCount();
//If no duplicate entry...
if ($checkifone == 1) {
echo "There is already an account with that name; please choose a different account number.";
} else {
//Confirms if passwords match
if ($password == $confirmation) {
$passhash = sha1($password);
$database = $db->query("
INSERT INTO accounts
VALUES (NULL , '$accountid', '$passhash', '65535', '0', '', '1', '0', '0', '1');
");
echo "Your account has been successfully created.";
//If passwords do not match
} else {
echo "Your passwords did not match, please try again.";
}
}
?>
</body>
</html>
当我加载页面,查看页面源,它似乎并没有表现出终止</body>
或终止</html>
标签。我追踪了我的代码,看不到任何缺少的分号或圆括号。对于我的生活,我无法弄清楚这一点。它只有在密码不匹配时才会正确显示终止标签(最底层的嵌套else语句)。
编辑;在任何人说出来之前,我知道mysql_escape_string
已被弃用。
edit2; database.php中看起来像...
<?php
$SERVER = "localhost";
$USERNAME = "redacted";
$PASSWORD = "redacted";
$DATABASE = "redacted";
$db = new PDO("mysql:dbname={$DATABASE}; host={$SERVER}", $USERNAME, $PASSWORD);
$db->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
?>
什么database.php中看起来不一样? –
确保你有[错误报告](http://php.net/manual/en/function.error-reporting.php):'error_reporting(E_ALL);'。 – Supericy
@RyanB,编辑了最初的帖子。 – gator