我不确定 POST 是否不起作用或功能是否不起作用。所以这里是一页的代码:
<?php require_once("includes/Functions.php"); ?>
<?php include("includes/front.php"); ?>
<div id="register">
<form action="Includes/Functions.php" method="post" name="createUser">
Username: <input type="text" name="user" maxlength="16"/><br />
Password: <input type="password" name="pass" maxlength="30"/><br />
Repeat password: <input type="password"/><br />
E-mail: <input type="email" name="mail"/><br />
<input type="submit" value="Next" />
</form>
<a href="/login.php">Log in</a>
</div>
</body>
</html>
<?php include("includes/footer.php"); ?>
这是functions.php的开头:
<?php require_once("connect.php"); ?>
<?php
if(isset($_POST["createUser"]) && isset($_POST["user"], $_POST["pass"], $_POST["mail"])){
call_user_func_array("createUser", array($_POST("user"), $_POST("pass"), $_POST("mail")));
}
使用 echo 故障排除方法我看到 echo 在代码中无处不在,但在我需要的功能中却没有。
这是功能:
function createUser ($username, $password, $email){
//Get from form
$username = $_POST["user"];
$password = $_POST["pass"];
$email = $_POST["mail"];
$hashedPassword = sha1($password);
//Submit to database
//make query
$query = ("INSERT INTO users ( username , email , hashPass ) VALUES ( '$username' , '$email' , '$hashedPassword')");
//use query
if (mysql_query($query, $connection)) {
//userMade.php
header("Location: ../userMade.php");
exit;
} else {
echo "<p>I suck!</p>";
echo "<p>".mysql_error()."</p>";
}
}
没有报告 PHP 或 MySQL 错误,我只看到一个空白页。