我在一个文件中有一个表单,index.php
它可以像这样发布到第二页:
<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>
提交是通过 jQuery 完成的,submitHandler
如下所示:
submitHandler: function(signupform) {
$(signupform).ajaxSubmit({
target:'#result',
success: function(){
$("#result").css("display","block");
$('#box').animate({'top':'-800px'},500,function(){
$('#overlay').fadeOut('fast');
$('#loginmain').hide();
});
}
})
}
结果显示在同一页面的 div 中,如下所示:
<div id="result" class="success_message" style="display: none"></div>
在第二页上functions.php
,我有需要在 div 中显示的内容。
现在的问题是我创建了第三个名为 db.php 的文件来执行数据库操作。
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";
}
}
虽然我在 index.php 中包含了 db.php,但查询并没有被执行,因为事实上,表格似乎不post
正确,因为如果我echo "test"
在if
语句后面放一个,它不会显示,但是如果我替换action="functions.php"
通过action=""
,一切正常,但随后submithandler
行为不正确。