我想更新我与人物的IDS数据库,但是当我把它们插入插槽,它不更新,我希望它更新的行。我的问题是你能在我怎么能code这个正确或修复我的错误,指出正确的方向我?
函数updateTeam(){
VAR团队='',插槽= [];
如果($('输入[名称= S0]')。VAL()!=){
slot.push($('输入[名称= S0])VAL());
}
如果($('输入[名称= S1]')。VAL()!=){
slot.push($('输入[名称= S1])VAL());
}
如果($('输入[名称= S2]')。VAL()!=){
slot.push($('输入[名称= S2])VAL());
}
$每个(插槽,功能(I,E){
如果(我== 0)团队= E;
其他团队=团队+,+ E;
});
$阿贾克斯({
网址:_path +/core/ajax.php
键入:POST,
数据:{F:setTeam',我:球队},
数据类型:JSON,
成功:功能(数据){
如果(data.error){
的errorMessage('错误:'+ data.error,data.error,data.error);
}
}
});
}
腓
函数干净($内容){
$内容= mysql_real_escape_string(用htmlspecialchars($内容));
返回$内容;
}
//更新用户的球队。
如果(使用isset($ _ POST ['F'])及和放大器; $ _ POST ['F'] =='updateTeam'){
如果(使用isset($ _ POST ['S0'])){
$ CID1 = $安全 - >清洁($ _ POST ['S0']);
} 其他 {
$ CID1 ='1';
}
如果(使用isset($ _ POST ['S1'])){
$ CID2 = $安全 - >清洁($ _ POST ['S1']);
} 其他 {
$ CID2 ='2';
}
如果(使用isset($ _ POST ['S2'])){
$ CID1 = $安全 - >清洁($ _ POST ['S2']);
} 其他 {
$ CID1 ='3';
}
$ updateTeam = $ DB->查询(更新帐户设置CID1 ='$ CID1',CID2 ='$ CID2',CID3 ='$ CID3'WHERE ID ='的$ id');
}
当我检查与谷歌浏览器的元素,它说我:1,5,2。说明如何将更新我的行,以便在I= $ CID1的1,5 = $ CID2,以及2 = CID3,是我的PHP code错了吗? HTML:
< DIV ID =droppable_slots级=current_team>
< DIV CLASS =插槽1> 1< / DIV>
<输入类型=隐藏名称=S0值=10>
< DIV CLASS =插槽2> 2'; / DIV>
<输入类型=隐藏名称=S1值=7>
< DIV CLASS =槽3>第3版; / DIV>
<输入类型=隐藏名称=S2值=3>
< / DIV>
解决方案
既然你发送一个CSV与我
,你需要从让你值的关键 $ _ POST ['我']
通过爆炸的,
。所以,你的code可以更新到类似 -
//更新用户的球队。
如果(使用isset($ _ POST ['F'])及和放大器; $ _ POST ['F'] =='updateTeam'){
//爆炸我交
如果(使用isset($ _ POST ['我'])){
$瓦尔斯=爆炸(,$ _ POST ['我']);
}
如果(使用isset($瓦尔斯[0])){
$ CID1 = $安全 - >清洁($瓦尔斯[0]);
} 其他 {
$ CID1 ='1';
}
如果(使用isset($瓦尔斯[1])){
$ CID2 = $安全 - >清洁($瓦尔斯[1]);
} 其他 {
$ CID2 ='2';
}
如果(使用isset($瓦尔斯[2])){
$ CID1 = $安全 - >清洁($瓦尔斯[2]);
} 其他 {
$ CID1 ='3';
}
$ updateTeam = $ DB->查询(更新帐户设置CID1 ='$ CID1',CID2 ='$ CID2',CID3 ='$ CID3'WHERE ID ='的$ id');
}
I want to update my database with the ids of characters, but when I drop them into the slot, it doesn't update the rows I want it to update. My question is can you point me in the right direction of how I can code this properly or fix my errors?
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
function clean($content) {
$content = mysql_real_escape_string(htmlspecialchars($content));
return $content;
}
//Update the user team.
if (isset($_POST['f']) && $_POST['f'] == 'updateTeam') {
if (isset($_POST['s0'])) {
$cid1 = $secure->clean($_POST['s0']);
} else {
$cid1 = '1';
}
if (isset($_POST['s1'])) {
$cid2 = $secure->clean($_POST['s1']);
} else {
$cid2 = '2';
}
if (isset($_POST['s2'])) {
$cid1 = $secure->clean($_POST['s2']);
} else {
$cid1 = '3';
}
$updateTeam = $db->query("UPDATE accounts SET cid1 = '$cid1', cid2 = '$cid2', cid3 = '$cid3' WHERE id = '$id'");
}
When i inspect the element with Google Chrome it says i:1,5,2. Show how would I update my rows so that the 1 in "i"= $cid1, the 5=$cid2, and the 2= cid3, is my php code wrong? Html:
<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>
解决方案
Since you are sending a csv with a the key of i
, you need to get your values from $_POST['i']
by exploding on the ,
. So your code could be updated to something like-
//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'");
}