当我尝试注册为用户时,我的register.php
文件为什么不做任何事情?我错过了什么吗?我已经确定使用config.db
我的注册页面:
<html>
<head>
<title> Register!</title>
</head>
<body>
<form action="register.php" method="POST">
<h1>Signup!</h1>
<p>Create an account:</p>
<div>
<label for="name">Name:</label>
<input type="text" id="name" name="firstname" value="" placeholder="First Name" class="login" />
</div> <!-- /field -->
<div>
<label for="email">Email Address:</label>
<input type="text" id="email" name="email" value="" placeholder="Email" class="login"/>
</div> <!-- /field -->
<div>
<label for="pass">Password:</label>
<input type="password" id="password" name="password" value="" placeholder="Password" class="login"/>
</div> <!-- /field -->
<div>
<label for="confirm_password">Confirm Password:</label>
<input type="password" id="confirmpassword" name="confirm_password" value="" placeholder="Confirm Password" class="login"/>
</div> <!-- /field -->
<input type="submit">Register</button>
</form>
</div> <!-- /content -->
</div> <!-- /account-container -->
</body>
</html>
我的php文件
<?php
include ("configdb.php");
function createUser()
{
$name = $_POST['name'];
$email = $_POST['email'];
$password = $_POST['password'];
$confirmpassword = $_POST['confirmpassword'];
echo "name";
if($password == $confirmpassword)
{
$query = "INSERT INTO Users (name,email,password) VALUES ('$name','$email','$password')";
$data = mysql_query ($query)or die(mysql_error());
if($data)
{
echo "YOUR REGISTRATION IS COMPLETED...";
}
}
else
{
echo "Passwords do not match";
}
}
if(isset($_POST['submit']))
{
createUser();
}
?>
答案 0 :(得分:10)
尝试为您的按钮命名。
<input type="submit" name="submit" value="Register">
当您通过表单发布信息时,您可以按名称调用特定输入。
在这种情况下,您正在寻找名为&#39;提交&#39;
的设置输入字段isset($_POST['submit'])
但是当你点击发布它的提交按钮时,你没有给出任何特定名称的输入,如果你给它起名字&#39;提交&#39;然后你通过“提交”来发布它,这意味着当你检查是否提交了#39;发布后,您会收到回复。