gpt4 book ai didi

php - 为什么这个 Ajax 表单提交不起作用?

转载 作者:可可西里 更新时间:2023-11-01 08:37:45 26 4
gpt4 key购买 nike

<分区>

下面的代码有什么问题?

警报返回成功,但没有向表中添加任何内容。形式:

<form id="Form_1" name="theform" method="post" action="">
<label for="email" class="emailLab">Email * </label>
<input type="email" name="email" id="email_id" autocorrect placeholder="Email" value="" />
<label for="phone">Phone </label>
<input type="tel" name="phone" id="phone_id" autocorrect placeholder="Phone" />
<input type="image" src="images/btn_enter.png" height="26" width="147" id="submit" data-inline="true" data-role="none" />
</form>

在提交时我调用这个函数:

function serverDB (){
// Define variables from input
var vEmail = document.getElementById('email_id').value;
var vPhone = document.getElementById('phone_id').value;

var theData = 'email=' + vEmail + '&phone=' +vPhone;
alert (theData);

$.ajax({
type: "POST",
url: "process.php",
data: theData,
success: function(){
alert ("Success");
}
});
}

PHP 代码:

<?
$email = $_POST['email'];
$phone = $_POST['phone'];
mysql_connect("host", "user", "password") or die(mysql_error());
mysql_select_db("sandbox_itouch") or die(mysql_error());
mysql_query("INSERT INTO `data` (email, phone) VALUES ('$email','$phone')");
?>

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com