Php Ajax调用不是';不要更新我的行
我想用字符ID更新我的数据库,但当我将它们放入插槽时,它不会更新我希望它更新的行。我的问题是,你能为我指出正确的方向,告诉我如何正确地编写代码或修复错误吗Php Ajax调用不是';不要更新我的行,php,jquery,html,ajax,Php,Jquery,Html,Ajax,我想用字符ID更新我的数据库,但当我将它们放入插槽时,它不会更新我希望它更新的行。我的问题是,你能为我指出正确的方向,告诉我如何正确地编写代码或修复错误吗 function updateTeam(){ var team = '', slot = []; if($('input[name=s0]').val()!=""){ slot.push($('input[name=s0]').val()); } if($('input[name=s1]').val()!=""){ slot
function updateTeam(){
var team = '', slot = [];
if($('input[name=s0]').val()!=""){
slot.push($('input[name=s0]').val());
}
if($('input[name=s1]').val()!=""){
slot.push($('input[name=s1]').val());
}
if($('input[name=s2]').val()!=""){
slot.push($('input[name=s2]').val());
}
$.each(slot, function(i,e){
if(i == 0) team = e;
else team = team + ',' + e;
});
$.ajax({
url : _path + "/core/ajax.php",
type : 'POST',
data : { f: 'setTeam', i: team},
dataType : 'json',
success : function(data) {
if(data.error){
errorMessage('Error: ' + data.error, data.error, data.error);
}
}
});
}
Php
当我用Google Chrome检查元素时,它显示i:1,5,2。演示如何更新我的行,以便“I”=cid1、5=cid2和2=cid3中的1是我的php代码错误吗?
Html:
1.
2.
3.
由于您发送的csv密钥为i
,因此您需要通过在,
上爆炸,从$\u POST['i']
获取您的值。因此,您的代码可以更新为-
//Update the user team.
if (isset($_POST['f']) && $_POST['f'] == 'updateTeam') {
//Explode the i post
if (isset($_POST['i'])) {
$vals = explode("," , $_POST['i'] );
}
if (isset($vals[0])) {
$cid1 = $secure->clean($vals[0]);
} else {
$cid1 = '1';
}
if (isset($vals[1])) {
$cid2 = $secure->clean($vals[1]);
} else {
$cid2 = '2';
}
if (isset($vals[2])) {
$cid1 = $secure->clean($vals[2]);
} else {
$cid1 = '3';
}
$updateTeam = $db->query("UPDATE accounts SET cid1 = '$cid1', cid2 = '$cid2', cid3 = '$cid3' WHERE id = '$id'");
}
<div id="droppable_slots" class="current_team">
<div class="slot 1">1</div>
<input type="hidden" name="s0" value="10">
<div class="slot 2">2</div>
<input type="hidden" name="s1" value="7">
<div class="slot 3">3</div>
<input type="hidden" name="s2" value="3">
</div>
//Update the user team.
if (isset($_POST['f']) && $_POST['f'] == 'updateTeam') {
//Explode the i post
if (isset($_POST['i'])) {
$vals = explode("," , $_POST['i'] );
}
if (isset($vals[0])) {
$cid1 = $secure->clean($vals[0]);
} else {
$cid1 = '1';
}
if (isset($vals[1])) {
$cid2 = $secure->clean($vals[1]);
} else {
$cid2 = '2';
}
if (isset($vals[2])) {
$cid1 = $secure->clean($vals[2]);
} else {
$cid1 = '3';
}
$updateTeam = $db->query("UPDATE accounts SET cid1 = '$cid1', cid2 = '$cid2', cid3 = '$cid3' WHERE id = '$id'");
}