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条)

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。