这是我的welcome_post.php
<?php
// include db connect class
require_once __DIR__ . '/db_connect.php';
// connecting to db
$db = new DB_CONNECT();
$response = array();
if (isset($_POST['user_email']) && isset($_POST['user_postcode'])){
$email = $_POST['user_email'];
$postcode = $_POST['user_postcode'];
// Insert data into mysql
$result = "INSERT INTO email (Email,Postcode) VALUES ('$email','$postcode')";
$insert_db = mysqli_query($db->getConnection(),$result);
}
?>
这是我的index.html
<form class="form-inline validate signup" action="welcome_post.php" method="post" role="form">
<div class="form-group">
<input type="email" class="form-control" name="user_email" id="exampleInputEmail1" placeholder="Enter your email address"><br><br>
<input type="email" class="form-control" name="user_postcode" id="exampleInputPostcode1" placeholder="Enter your postcode">
</div>
<br><br>
<input type="submit" name="subscribe" value="Get notified when we cover new area!" class="btn btn-theme">
</form>
我的index.html里面包含javascript:
$(document).ready( function () {
$('#wrapper').height($(document).height());
// I only have one form on the page but you can be more specific if need be.
var $form = $('form');
if ( $form.length > 0 ) {
$('form input[type="submit"]').bind('click', function ( event ) {
if ( event ) event.preventDefault();
// validate_input() is a validation function I wrote, you'll have to substitute this with your own.
if ( $form.validate() ) { register($form); }
});
}
});
function appendResult(userText , className, iconClass){
var resultHTML = "<div class='stretchLeft result "+ className + "'>" + userText + " <span class='fa fa-" + iconClass + "'></span>" + "</div>";
$('body').append(resultHTML);
$('.result').delay(10000).fadeOut('1000');
}
function register($form) {
$.ajax({
type: $form.attr('method'),
url: $form.attr('action'),
data: $form.serialize(),
cache : false,
dataType : 'json',
contentType: "application/json; charset=utf-8",
error : function(err) { alert("Could not connect to the registration server. Please try again later."); },
success : function(data) {
if (data.result != "success") {
appendResult('Wrong Email Or You Are Already Registered, Try Again', 'error', 'exclamation');
} else {
// It worked, carry on...
appendResult('Successful, Check Your Email For Confirmation ', 'success', 'check');
}
}
});
}
当我按下提交按钮时,它无法插入数据库并显示javascript警告&#34;无法连接到注册服务器。稍后再试。&#34;
我试过运行php代码,没有错误。