У меня есть форма в файле index.php
, что сообщения на второй странице, как это:POST не ведет себя правильно с MySQL
<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";
}
}
Хотя я включил db.php в index.php, запросы не получают выполняются, потому что на самом деле, кажется, что форма не post
правильно, потому что если я ставлю echo "test"
после if
заявления, он не отображается, но если я заменю action="functions.php"
на action=""
, все будет работать, но тогда submithandler
не будет корректно вести себя.
Включите db.php в свой файл functions.php? –
о, я не сделал! Это решило проблему. Спасибо @BjornSchijff !! – Suvimo
Добро пожаловать :-). –