登记表不回应

时间:2014-02-28 06:57:44

标签: php if-statement

我是PHP的新手,当你点击提交时我无法得到这个if语句。我的编辑器没有显示代码的任何错误,它似乎工作正常,除了它没有回应错误。

<html>
<LINK rel='stylesheet' href='style.css' type='text/css'>

<?php
$submit = $_POST['submit'];
$username = strip_tags($_POST['username']);
$password = strip_tags($_POST['password']);
$repeatpassword = md5(strip_tags($_POST['repeatpassword']));

$date = date('Y-m-d');
echo $date;
if ($sumbit)
{
    if ($username&&$password&&$repeatpassword)
    {
        $password = md5($password);
        $repeatpassword = md5($repeatpassword);

        if ($password==$repeatpassword) 
        {
            if(strlen($username)>25)
            {
                echo 'Length of username must be less than 25 charcters';
            }
            else 
            {
                if (strlen($password)>25||strlen($password)<6)
                {
                    echo 'Your password must be 6 to 25 characters long';
                }
                else 
                {
                    echo 'Success!';
                }
            }
        }
        else 
        {
            echo 'Passwords do not match';
        }

    }
    else
        echo 'Fill in all the fields';
}
?>

<form action='register.php' method='POST'>
    <table>
        <tr>
            <td>Username</td><br />
        </tr>  
        <tr>  
            <td><input type='text' name='username'></td><br />
        </tr> 
        <tr>
            <td>Password</td><br />
        </tr>
        <tr>    
            <td><input type='password' name='password'></td><br />
        </tr>    
        <tr>    
            <td>Repeat Password</td><br />
        </tr>
        <tr>
            <td><input type='password' name='repeatpassword'></td><br />
        </tr>
    </table>
        <p>
            <input type='submit' name='submit' value='Register'>
</form>

</html>

6 个答案:

答案 0 :(得分:3)

有一个错字

它的

if ($sumbit)

应该是

if ($submit)

答案 1 :(得分:1)

在代码的开头添加:

ini_set("display_errors", true);
error_reporting(E_ALL);

您必须启用错误报告,默认情况下已关闭。反正:

if ($sumbit)

我想你想检查一下它的设置。 php中的函数称为isset(),因此您的代码将是:

if(isset($submit)) {}

答案 2 :(得分:1)

试试这个,它可能对你有帮助。

if (isset($_POST['submit']))
{
    $submit = $_POST['submit'];
    $username = strip_tags($_POST['username']);

    $password = strip_tags($_POST['password']);
    $repeatpassword = md5(strip_tags($_POST['repeatpassword']));

    $date = date('Y-m-d');
    echo $date;
    if ((isset($username))&&(isset($password))&&(isset($repeatpassword)))
    {
        $password = md5($password);
        $repeatpassword = md5($repeatpassword);

        if ($password==$repeatpassword) 
        {
            if(strlen($username)>25)
            {
                echo 'Length of username must be less than 25 charcters';
            }
            else 
            {
                if (strlen($password)>25||strlen($password)<6)
                {
                    echo 'Your password must be 6 to 25 characters long';
                }
                else 
                {
                    echo 'Success!';
                }
            }
        }
        else 
        {
            echo 'Passwords do not match';
        }


    }
    else
        echo 'Fill in all the fields';

}

AND表格使用:

<form action='' method='POST'>
    <input type='submit' name='submit' value='Register'>
</form>

答案 3 :(得分:0)

试试这个

if(isset($_POST['submit']))
{
  if (isset($_POST['username'], $_POST['password'], $_POST['repeatpassword']))
  {
    $username = strip_tags($_POST['username']);

    $password = strip_tags($_POST['password']);
    $repeatpassword = md5(strip_tags($_POST['repeatpassword']));

而不是

if ($sumbit)
{
   if ($username&&$password&&$repeatpassword)
   {

答案 4 :(得分:0)

您正在使用提交并使用提交

if ( !empty($submit) ){


{

答案 5 :(得分:0)

有一个md5的repeatpassword被执行两次,md5的密码被执行一次。所以if条件失败

if ($password==$repeatpassword)

之前如果提交条件

$password = strip_tags($_POST['password']);
$repeatpassword = md5(strip_tags($_POST['repeatpassword']));

内部如果提交条件

$password = md5($password);
$repeatpassword = md5($repeatpassword);