-2
我試圖插入多個複選框值到數據庫使用Ajax,但我不知道我能爲這種方法做什麼。我用這些代碼試了一下。在PHP + AJAX中插入多個複選框的值
<h3 class="page-header">International Language</h3>
<div class="form-group">
<label class="col-md-3 control-label" for="">Chinese</label>
<div class="col-md-7">
<div class="checkbox checkbox-inline">
<label>
<input type="checkbox" id="chinese" name="chk[]" value="chinees">
</label>
</div>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label" for="">English</label>
<div class="col-md-7">
<div class="checkbox checkbox-inline">
<label>
<input type="checkbox" id="english" name="chk[]" value="english">
</label>
</div>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label" for="">English, Welsh</label>
<div class="col-md-7">
<div class="checkbox checkbox-inline">
<label>
<input type="checkbox" id="englishwelsh" name="chk[]" value="englishwelsh">
</label>
</div>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label" for="">Estonian</label>
<div class="col-md-7">
<div class="checkbox checkbox-inline">
<label>
<input type="checkbox" id="estonian" name="chk[]" value="estonian">
</label>
</div>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label" for="">French</label>
<div class="col-md-7">
<div class="checkbox checkbox-inline">
<label>
<input type="checkbox" id="french" name="chk[]" value="frnch">
</label>
</div>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label" for="">Greek</label>
<div class="col-md-7">
<div class="checkbox checkbox-inline">
<label>
<input type="checkbox" id="greek" name="chk[]" value="greek">
</label>
</div>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label" for="">Latvia</label>
<div class="col-md-7">
<div class="checkbox checkbox-inline">
<label>
<input type="checkbox" id="latvia" name="chk[]" value="latvia">
</label>
</div>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label" for="">Malay</label>
<div class="col-md-7">
<div class="checkbox checkbox-inline">
<label>
<input type="checkbox" id="malay" name="chk[]" value="malay">
</label>
</div>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label" for="">Maltese</label>
<div class="col-md-7">
<div class="checkbox checkbox-inline">
<label>
<input type="checkbox" id="maltese" name="chk[]" value="maltese">
</label>
</div>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label" for="">Swedish</label>
<div class="col-md-7">
<div class="checkbox checkbox-inline">
<label>
<input type="checkbox" id="swedish" name="chk[]" value="swedish">
</label>
</div>
</div>
</div>
$('#btn_ielts_assesment_next').click(function()
{
var id =$("#hlast_id").val();
var joboffered=$('#joboffered').val();
var givenielts=$('#givenielts').val();
var ieltsband=$('#ieltsband').val();
var ieltspassingyear=$('#ieltspassingyear').val();
var chiness=$('#chinese').val();
var english=$('#english').val();
var englishwelsh=$('#englishwelsh').val();
var estonian=$('#estonian').val();
var french=$('#french').val();
var greek=$('#greek').val();
var latvia=$('#latvia').val();
var malay=$('#malay').val();
var maltese=$('#maltese').val();
var swedish=$('#swedish').val();
$.post('<?php echo SERVER_ADMIN_URL;?>ajax/ielts_ajax.php',{action:"btn_ielts_assesment_next",hlast_id:id, joboffered:joboffered,givenielts:givenielts,ieltsband:ieltsband,ieltspassingyear:ieltspassingyear,chiness:chiness,
english:english,englishwelsh:englishwelsh,estonian:estonian,french:french,greek:greek,latvia:latvia,malay:malay,maltese:maltese ,swedish:swedish},function(data)
{
});
});
<php>
<?php
if($_POST['action'] == 'btn_ielts_assesment_next'){
$table='assessment';
//$lang=();
$language=implode(",");
$set2=array(
'joboffered'=>$_POST['joboffered'],
'givenielts'=>$_POST['givenielts'],
'ieltsband'=>$_POST['ieltsband'],
'ieltspassingyear' => $_POST['ieltspassingyear'],
'languageknown'=>$language);
$main_where=array('id'=>$_POST['hlast_id']);
$obj_conn->Update($table,$set2,$main_where, $exclude = '');
}
?><!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
</body>
</html>
你能幫我嗎?它不工作。提前致謝!
有很多方法可能會出錯。你嘗試過調試嗎? – aldux
他們只是字符串。你可以像插入任何其他字符串一樣將它們插入數據庫,使用'INSERT'查詢和適當的[sql注入攻擊](http://bobby-tables.com)避免方法。 –