我一直在为我的网站制作一个注册页面,并试图找出为什么在我按下注册按钮后此代码似乎总是回显“尚未提交任何内容”。 HTML 表单的编码方式是否存在问题?或者 php 接收它们的方式?
<?php
session_start();
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
if (isset($_POST['uname'])) {
include_once("dbconnect.php");
$uname = strip_tags($_POST["uname"]);
$pwd = strip_tags($_POST["pword"]);
$pwdtwo = strip_tags($_POST["pwordtwo"]);
$unamecheck = mysqli_real_escape_string($dbCon, $usname);
$pwdcheck = mysqli_real_escape_string($dbCon, $paswd);
$msg = "Something submitted!";
// Are the username and password legal?
if($pwd == $pwdcheck && $unamecheck == $uname) {
// Is the password confirmed?
if($pwd == $pwdtwo){
$sql = "SELECT userID, username, password FROM users WHERE username = '$usname' LIMIT 1";
$query = mysqli_query($dbCon, $sql);
$row = mysqli_fetch_row($query);
// Check to make sure that the username doesn't already exist.
if(is_null($row[1])){
$uricheck = strrchr($uname, "@");
$uriedu = "@my.uri.edu";
// Check that it is a uri email account.
if($uricheck !== false && strcmp($uricheck, $uriedu) === 0){
$sql = "INSERT INTO `campuskey`.`users` (`userID`, `username`, `password`) VALUES (NULL, '$uname', '$pwd')";
mysqli_query($dbCon, $sql);
// Set session variables
$_SESSION['username'] = $usname;
$msg = "You have now registered!";
// Now direct to users feed
header("Location: user.php");
} else {
$msg = "That is not a valid uri email.";
}
} else {
$msg = "That email is already in use, fuckface!";
}
}
else {
$msg = "Either you have typing tourettes or your keyboard's fucked up. Those passwords don't match up";
}
} else {
$msg = "<h2>What the fuck did you type? That shit ain't legal!</h2>";
}
} else {
$msg = "Nothing submitted yet.";
}
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<link href="css/reset.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<title>Campus Key, Page</title>
</head>
<body>
<header>
<a href="index.html"> <img src="logowhite.png" alt="Campus Key" style="width:150px;height:41px"></a>
</header>
<nav class="navigation">
<div class="non_registerd">
<h2><a class="button" href="login.php">Already have an account? Login here!</a></h2>
</div>
</nav>
<form>
<?php
echo $msg;
?><br>
URI Email: <input class="input" id="email" type="text" name="uname" placeholder="your@my.uri.edu" size="30" required><br>
Password: <input class="input" id="pass" type="text" name="pword" size="30" required><br>
Confirm Password: <input class="input" type="text" name="pwordtwo" size="30" required><br>
<input class="button" type="Submit" name="submit" value="Register"><br>
</form>
</body>
<footer>
<p><FONT color="#ffffff">Campus Key © Whatever We Want</color></p>
</footer>
</html>
最佳答案
您的表单标记不包含任何操作或方法 atrr 您必须首先像这样定义它们:
<form method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>">
关于php - 注册页面 HTML 未将表单数据发送到 php 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26919306/