我的isset函数没有运行

时间:2013-10-25 16:41:54

标签: php html registration

我有一些PHP的经验,但是我在创建的登录和注册表单上遇到了问题。我的isset()函数没有识别出按下了提交按钮,即使名称是正确的:

if (isset($_POST['register'])){
$fn = mysql_real_escape_string($_POST['firstname']);
$ln = mysql_real_escape_string($_POST['lastname']);
$regusername = mysql_real_escape_string($_POST['reg_username']);
$regemail = mysql_real_escape_string($_POST['reg_email']);
$regpass1 = mysql_real_escape_string($_POST['reg_password']);
$regpass2 = mysql_real_escape_string($_POST['reg_password2']);
$date = date('Y','m','d');

if(empty($fn)){
    $action['result'] = 'error'; 
    array_push($text, "<script type='text/javascript'>alert('Please input your first name!');</script>");
}

if(empty($ln)){
    $action['result'] = 'error'; 
    array_push($text, "<script type='text/javascript'>alert('Please input your last name!');</script>");
}

if(empty($regusername)){
    $action['result'] = 'error'; 
    array_push($text, "<script type='text/javascript'>alert('Please input a username!');</script>");
}

if(empty($regemail)){
    $action['result'] = 'error'; 
    array_push($text, "<script type='text/javascript'>alert('Please input your email!');</script>");
}

if(empty($regpass1)){
    $action['result'] = 'error'; 
    array_push($text, "<script type='text/javascript'>alert('Please input a password!');</script>");
}

if(empty($regpass2)){
    $action['result'] = 'error'; 
    array_push($text, "<script type='text/javascript'>alert('Please repeat your password!');</script>");
}

if($regpass1 != $regpass2){
    $action['result'] = 'error';
    array_push($text, "<script type='text/javascript'>alert('Passwords dosen't match!');</script>");
}

if($action['result'] != 'error'){
    $hash = hash('sha256', $regpass1);

    //Creating a salt for the password
    function createSalt(){
        $string = md5(unigid(rand(), true) );
        return substr($string, 0, 3); 
    }
    $salt = createSalt();
    $hash = hash('sha256', $salt . $hash);
}

$action['text'] = $text;

//Sending data to MySQL
$query = "INSERT INTO 'members' (firstname, lastname, username, email, password, salt, sign-up-date )
            VALUES('$fn', '$ln', '$regusername', '$regemail', '$regpass1', '$salt' , '$date');";

mysql_query($query);

if($query){
    echo "<script type='text/javascript'>alert('User was added!');</script>";
    mysql_close();
}
else{
    $action['result'] = 'error';  
    array_push($text, "<script type='text/javascript'>alert('User could not be added to the database.');</script>" .  mysql_error());   
}
}
//Registration END

报名表:

<div id="register_user" class="form-action hide" action="" method="post">

                <form>
                    <ul>
                        <li>
                            <input type="text" placeholder="First Name" name="firstname"/>
                        </li>
                        <li>
                            <input type="text" placeholder="Last Name"name="lastname"/>
                        </li>
                        <li>
                            <input type="text" placeholder="Username" name="reg_username"/>
                        </li>
                        <li>
                            <input type="text" placeholder="Email" name="reg_email"/>
                        </li>
                        <li>
                            <input type="password" placeholder="Password" name="reg_password"/>
                        </li>
                        <li>
                            <input type="password" placeholder="Repeat password" name="reg_password2"/>
                        </li>
                        <li>
                            <input type="submit" value="Sign Up" class="button" name="register"/>
                        </li>
                    </ul>
                </form>
            </div>

请帮我解决这个问题:)

1 个答案:

答案 0 :(得分:0)

注意: action标记中使用的method<form>

<div id="register_user" class="form-action hide">

                <form action="" method="post">
                    <ul>
                        <li>
                            <input type="text" placeholder="First Name" name="firstname"/>
                        </li>
                        <li>
                            <input type="text" placeholder="Last Name"name="lastname"/>
                        </li>
                        <li>
                            <input type="text" placeholder="Username" name="reg_username"/>
                        </li>
                        <li>
                            <input type="text" placeholder="Email" name="reg_email"/>
                        </li>
                        <li>
                            <input type="password" placeholder="Password" name="reg_password"/>
                        </li>
                        <li>
                            <input type="password" placeholder="Repeat password" name="reg_password2"/>
                        </li>
                        <li>
                            <input type="submit" value="Sign Up" class="button" name="register"/>
                        </li>
                    </ul>
                </form>
            </div>