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 post
correctly 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.