我是PHP的新手并尝试使用提交按钮进行注册表单我已经使用了将处理用户输入详细信息的操作意味着用户名长度和密码长度但是此功能未被调用提交按钮 my无论我在“SignUp.php”页面中写过什么,浏览器都会显示整个代码。有人请帮我...... InternHtml.php代码
<div id="wrapper" class="wrapperClass">
<fieldset>
<legend class="regLagendClass">Registration Form</legend>
<form id="registrationForm" method="POST" action="SignUp.php">
<!-- <form id="registrationForm" method="get" action="">-->
<div class="divClass">
<label for="firstName" class="labelClass">First Name:</label>
<input type="text" name="fName" class="textboxClass" id="firstName" placeholder="Your First Name"/>
</div>
<div class="divClass">
<label for="lastName" class="labelClass">Last Name:</label>
<input type="text" name="lName" id="lastName" class="textboxClass" placeholder="Your Last Name"/>
</div>
<div class="divClass">
<label for="userName" class="labelClass">User Name:</label>
<input type="text" name="userName" id="userName" class="textboxClass" placeholder="Your User Name" required/>
</div>
<div class="divClass">
<label for="password" class="labelClass">Password:</label>
<input type="password" id="password" name="password" class="textboxClass" placeholder="Type Password" required/>
</div>
<div class="divClass">
<label for="cPassword" class="labelClass">Confirm Password:</label>
<input type="password" id="cPassword" name="userPassword" class="textboxClass" placeholder="Retype Password"/>
</div>
<div class="divClass">
<label for="gender" class="labelClass">Choose Gender:</label>
<select name="gender" class="textboxClass">
<option>Male</option>
<option>Female</option>
</select>
</div>
<div class="divClass">
<label class="labelClass" for="dob">Date of Birth:</label>
<input type="date" id="dob" class="textboxClass" placeholder="Your Date of Birth"/>
</div>
<div class="divClass">
<!-- <label for="country" class="labelClass">Country:</label>
<input type="text" id="country" class="textboxClass"/>-->
<label for="emailId" class="labelClass">Email Id:</label>
<input type="email" id="emailId" name="userEmail" class="textboxClass"/>
</div>
<div class="divClass">
<input type="submit" value="Sign Up"/>
</div>
</form>
</fieldset>
</div>
SignUp.php代码
function registerFunction()
{
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$uname = $_POST['userName'];
$pword = $_POST['password'];
$errorMessage;
$uname = htmlspecialchars($uname);
$pword = htmlspecialchars($pword);
$uLength = strlen($uname);
$pLength = strlen($pword);
if($uLength >= 0 && $uLength <= 10)
{
$errorMessage = "UserName Length";
}
else
{$errorMessage = "No error in UserName Length";
}
if($pLength >= 0 && $pLength <= 10)
{
$errorMessage = "password Length";
}
else
{$errorMessage = "No error in password Length";
}
if(strlen($errorMessage) == "")
{
echo "There is no error::::NO Error Message" .$errorMessage;
}
else
{
echo "There is error::::Error Message" .$errorMessage;
}
}
}
答案 0 :(得分:2)
首先,您根本没有在任何地方呼叫registerFunction()
..
只需像这样重写你的SignUp.php
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$uname = $_POST['userName'];
$pword = $_POST['password'];
$errorMessage;
$uname = htmlspecialchars($uname);
$pword = htmlspecialchars($pword);
$uLength = strlen($uname);
$pLength = strlen($pword);
if($uLength >= 0 && $uLength <= 10)
{
$errorMessage = "UserName Length";
}
else
{$errorMessage = "No error in UserName Length";
}
if($pLength >= 0 && $pLength <= 10)
{
$errorMessage = "password Length";
}
else
{$errorMessage = "No error in password Length";
}
if(strlen($errorMessage) == "")
{
echo "There is no error::::NO Error Message" .$errorMessage;
}
else
{
echo "There is error::::Error Message" .$errorMessage;
}
}
答案 1 :(得分:0)
您需要致电registerFunction()
函数 SignUp.php