我正在尝试仅使用PHP创建注册系统.这是一个例子.但是我想我做错了什么.我试图在*帖子中找到类似的解决方案,但是没有任何确切的解决方案.如果有人可以帮助我在下面的代码中找到错误,那将是非常有用的.
<?php
// POST HANDLER -->
if(isset($_POST['registerForm']))
{
conFunc(); // Connection Function
$userid = $_POST['userid'];
$name = $_POST['name'];
$getUserId = mysql_query("SELECT * FROM `user` WHERE `userid` = '".$userid."'");
$id = mysql_fetch_array($getUserId);
if($id)
{
echo "This User ID is Already Available on the System, Please Choose Something Else!";
}
else
{
$query = mysql_query("INSERT INTO `user` (`userid`, `name`");
if($query)
{
echo "A New User is Registered Successfully:<br /><br />";
echo "<b>User ID:</b> " . $userid . "<br />";
echo "<b>User Name:</b> " . $name . "<br />";
}
else
{
echo "There is an Error while Saving: " . mysql_error();
echo "<br />Please click on Create User from menu, and try again<br /><br />.";
}
}
exit;
}
// POST HANDLER -->
?>
<!-- FORM GOES BELOW -->
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post" name="registerForm">
<table style="width: 100%">
<tr>
<td>User ID</td>
<td><input name="userid" type="text" style="width: 300px" /><br /></td>
</tr>
<tr>
<td>Name</td>
<td><input name="name" type="text" style="width: 300px" /><br /></td>
</tr>
<tr>
<td></td>
<td><input style="width: 130px; height: 30px" type="submit" name="submit" value="Register Now" /><br /></td>
</tr>
</table>
</form>
解决方法:
您必须检查提交按钮是否设置.
if(isset($_POST['registerForm']))
应该
if(isset($_POST['submit'])) {
// your php code
} else {
// your html code
}