我有一个网络表单,将一系列无线电输入序列化为以下字符串(其中数字代表GameID,学校名称代表获胜者):
1=Boise+State&2=Michigan+State&4=Florida&3=Memphis
我使用AJAX帖子将其传递给.php脚本以插入数据库 我无法解析" GameID"和#34;获胜者"序列化字符串中的数据和变量。我希望它进入INSERT语句,如下所示。
SCRIPT
$('#saveBtn').click(function(){
confidence = $('#confidenceSort').sortable('serialize');
winners = $('#winners').serialize();
$.post("postpicks.php", confidence,
function(result){
//do stuff
})
$.post("postpicks.php", winners,
function(result){
//do stuff
})
});
PHP
$a1=array("=","&");
$a2=array("=>",",");
$dataArray = array(str_replace($a1,$a2,$_POST['winners']));
foreach ($dataArray as $key => $value){
$query = "REPLACE INTO picks SET
winner = '".$value."'
WHERE gameid = ".$key.",
AND userid='".$uid."'";
$result = mysqli_query($link, $query);
if (!$result) {errmsg('A database error occurred. Please contact Ryan.');}
$i++;
}