以下功能不起作用。使用表单操作将数据直接发送到 php 脚本时会更新数据库,但是通过 AJAX 函数将数据发送到 php 脚本时,数据库不会更新,但我会收到成功消息。
阿贾克斯
<script src="ajax.min.js" type="text/javascript"></script>
<script type="text/javascript">
function addRecord()
{
var first_first_name= $('#first_firstname').val();
var first_last_name = $('#first_lastname').val();
var team_name = $('#team_name').val();
if(team_name == ' '){
$('#propspectDiv').html('Enter A Valid Name');
$('#TeamName').addClass('error');
return;
}else{
$('#TeamName').removeClass('error');
$('#propspectDiv').removeClass('error');
$('#propspectDiv').html('Entering Team Name.<img src="images/processing.gif" />');
$.ajax({url : 'rpmh_open_update_prospects.php',
data:{
"team_name" : team_name,
"first_firstname" : first_first_name,
"first_lastname" : first_last_name,
},
success : function(data){
window.setTimeout(function()
{
$('#propspectDiv').html('Team Name Added!');
$('#data').css("display","block");
$('#data').html(data);
}, 2000);
}
});
}
}
</script>
The php
$stmt = $mysqli->prepare("UPDATE mytable SET Team=? WHERE FirstName = ? AND LastName = ?");
$stmt->bind_param('sss', $team, $first, $last);
$team = $_POST['team_name'];
$first = $_POST['first_firstname'];
$last = $_POST['first_lastname'];
/* execute prepared statement */
$stmt->execute();
/* close statement and connection */
$stmt->close();