dongxizhe9755 2013-07-03 14:29
浏览 15
已采纳

POST不能正确使用mysql

I have a form in a file index.php that posts to a second page like this:

    <form method="post" id="signupform" name="signupform" action="functions.php">
        <label for="user_id">Username:</label><span id="asterix">*</span> <br>
        <input name="user_id" type="text" id="user_id" required><br><br>
        <label for="new_password">Password:</label><span id="asterix">*</span> <br>
        <input name="new_password" type="password" id="new_password" required><br><br>
        <label for="confirm_password">Confirm password:</label><span id="asterix">*</span> <br>
        <input name="confirm_password" id="confirm_password" type="password" required><br><br>
        <label for="new_email">Email:</label><span id="asterix">*</span> <br>
        <input name="new_email" id="new_email" type="email" required>
        <input hidden="hidden" name="action" value="signup">
        <br><br>
        <input id="createaccount" type="submit" value="Create account">
    </form>

The submit is done through jQuery submitHandler like this:

                submitHandler: function(signupform) {
                $(signupform).ajaxSubmit({

                    target:'#result',
                    success: function(){
                        $("#result").css("display","block");
                        $('#box').animate({'top':'-800px'},500,function(){
                            $('#overlay').fadeOut('fast');
                            $('#loginmain').hide();
                        });

                    }
                })
            }

The result is shown in a div in the same page as follows:

<div id="result" class="success_message" style="display: none"></div>

On the second page, functions.php, I have what needs to be displayed in the div.

Now the problem is that I created a third file called db.php to do database operations.

    if (isset($_POST['action']) && $_POST['action'] == "signup") {
    $user_id      = mysql_real_escape_string($_POST["user_id"]);
    $new_password = md5(mysql_real_escape_string($_POST["new_password"]));
    $new_email    = mysql_real_escape_string($_POST["new_email"]);

    $create_account = "INSERT INTO users(username, email, password ) VALUES ('" . $user_id . "','" . $new_password . "','" . $new_email . "')";
    if($create_account){echo "done";}else echo "failed";
    if(mysqli_query($str, $create_account)){
        echo "successful insert";
    }
 }

Although I have included db.php in the index.php, the queries do not get executed because in fact, it seems that the form does not postcorrectly because if I put an echo "test" after the if statement, it does not show, but if I replace the action="functions.php" by action="", things work, but then the submithandler does not behave correctly.

  • 写回答

2条回答 默认 最新

  • doukang5966907 2013-07-03 19:27
    关注

    You should include db.php in functions.php as well in order to have these functions work there as well.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改