php注册,不会正常工作。

时间:2013-05-26 14:00:31

标签: php mysql

我正在制作一个页面,您可以将自己注册到我们的数据库中,以便稍后您可以使用这些信息登录网站并访问这些信息。 这是我的这部分代码:

 <?php
        if (isset($_POST['inputFirst']) && isset($_POST['inputLast']) && isset($_POST['inputUsername']) && isset($_POST['inputPassword'])) {
            print "<p>you have registered sucessfully</p>";
            $fname = $_POST['inputFirst'];
            $lname = $_POST['inputLast'];
            $email = $_POST['inputemail'];
            $username = $_POST['inputUsername'];
            $password = $_POST['inputPassword'];
            $tele = "0811111222";
            $add ="testing";
            $loc = "location";

            include 'opendb.php';
            $sql = "insert into Home_User (Fiest_Name,Last_Name,User_ID,Password,Email,Tel,Address,Island,Location) values ('$_POST[inputFirst]','$_POST[inputLast]','$_POST[inputUsername]','$_POST[inputPassword]','$_POST[inputemail]')";
            $result = mysql_query($sql,$conn) or die(mysql_error());
            print "<p>you have registered sucessfully</p>";
            print "<a href='index.php'>go to login page</a>";
        }           

        else print '<form class="form-horizontal" action="registration.php" method=post>
            <h1> not registered yet</h1>
            <h2>welcome to the registration page</h2>
            please fill in the registration details to create an account. <br/><br/>
            <div class="heading">
                <h4 class="form-heading">Home user registration</h4>
            </div>
                      <div class="control-group">
                        <label class="control-label" for="inputFirst">First Name</label>
                        <div class="controls">
                            <input type="text" id="inputFirst" placeholder="E.g. Ashwin">
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label" for="inputLast">Last Name</label>
                        <div class="controls">
                            <input type="text" id="inputLast" placeholder="E.g. Hegde">
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label" for="inputemail">Email</label>
                        <div class="controls">
                            <input type="text" id="inputemail" placeholder="E.g. hotloving@hotmail.com">
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label" for="inputUsername">Username</label>
                        <div class="controls">
                            <input type="text" id="inputUsername" placeholder="E.g. ashwinhegde">
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label" for="inputPassword">Password</label>
                        <div class="controls">
                            <input type="password" id="inputPassword" placeholder="Min. 8 Characters">
                        </div>
                    </div>

                     <div class="control-group">
                        <label class="control-label" for="inputTell">Telephone</label>
                        <div class="controls">
                            <input type="text" id="inputTell" class="bfh-phone" data-format="(ddd) ddd-dddd">
                        </div>
                    </div>

                    <div class="control-group">
                        <div class="controls">
                            <label class="checkbox">
                                <input type="checkbox"> I agree all your <a href="#">Terms of Services</a>
                            </label>
                            <button type="submit" class="btn btn-success">Sign Up</button>
                            <button type="button" class="btn">Help</button>
                        </div>
                    </div>
        </form>';
        ?>

$ tele,$ add,$ loc是数据库中的其他值,我还没有使用它们。

当我按下注册时它没有做什么只是刷新页面,它不会给我这个:

您已成功注册。

我不确定出了什么问题,与数据库的连接或者是什么。请帮忙。

2 个答案:

答案 0 :(得分:3)

指定输入的名称,在第一个输入if:'inputFirst','inputLast','inputUsername','inputPassword'。

<input type="text" id="inputLast" name="inputLast" placeholder="E.g. Hegde">
<input type="text" id="inputFirst" name="inputFirst" placeholder="E.g. Ashwin">

你只有一个id:

<input type="text" id="inputFirst" placeholder="E.g. Ashwin">

答案 1 :(得分:2)

您的代码容易受到SQL注入攻击。您应该尝试将mysql_real_escape_string用于所有POST和GET请求,例如

$email = mysql_real_escape_string($_POST['inputemail']);

并且您在输入文本中缺少name属性;它应该是

<input type="text" id="inputFirst" name="inputFirst" placeholder="E.g. Ashwin">

您无需打印

print "<p>you have registered sucessfully</p>"; //don't need before the insertion

您应首先检查插入是否成功,然后您应该打印它。

$result = mysql_query($sql, $conn);

if($result) {
    print "<p>you have registered sucessfully</p>";
    print "<a href='index.php'>go to login page</a>";
} else {
    die(mysql_error());
}