我的表单中有多个名称为itm的复选框 这显然将所有选中的值存储到数组$ _POST [' itm'] []
我的问题是我想要以格式存储在相关列中的数组值 1:88:99:77: :是分隔符,数字是复选框值
然而,当我提交表单时,它只显示Array() 然后我尝试了serialize()函数..而不是我想要的
所以任何人都可以帮忙
以下代码``
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$forname = $_POST['forename'];
$surname = $_POST['surname'];
$newfname = str_replace("'","",$_POST['forename']);
$newsname = str_replace("'","",$_POST['surname']);
$year = date('y');
$month = date('m');
$day = date('d');
$username = $newfname.$newsname.$month.$year;
// Perform queries
$addq = mysqli_query($con,"INSERT INTO `workshop-jobs` (wsjid, wscid, wsccid, summary, jobtype, caterhamwarrantyid, worktobedone, quoteinvref, datearrived, workstartdate, workstarttime, workfinishdate, hours, reqbydate, technician, status, completed, invoiced, notes)
VALUES ('','$_POST[wscid]','$_POST[wsccid]','$_POST[summary]','$_POST[jobtype]','$_POST[caterhamwarrantyid]','$_POST['itm']','$quoteinvref','$_POST[datearrived]','$_POST[workstartdate]','$_POST[workstarttime]','$_POST[workfinishdate]','0','$_POST[reqbydate]','$_POST[technician]','$_POST[status]','0','0','$_POST[notes]')");
if($addq){
$last_id = $con->insert_id;
$lastid = mysqli_query($con,"SELECT * FROM `users` WHERE userid = '$last_id'");
$lastidr = mysqli_fetch_assoc($lastid);
header("Location: addjobbat.php?wscid=$last_id");
}
echo mysqli_error($con);
mysqli_close($con);
表格代码
<div class="panel-body">
<input name="itm[]" class="serviceitem" type="checkbox" value="1:">
1000 / 3 Month Service ( Sigma / Duratec / CSR )<br>
<input name="itm[]" class="serviceitem" type="checkbox" value="2:">
1000 / 3 Month 620 Service<br>
<input name="itm[]" class="serviceitem" type="checkbox" value="3:">
Annual Service ONE ( Sigma / Duratec / CSR )<br>
<input name="itm[]" class="serviceitem" type="checkbox" value="4:">
Annual Service ONE ( Duratec R500 )<br>
<input name="itm[]" class="serviceitem" type="checkbox" value="5:">
620 Annual Service ONE<br>
<input name="itm[]" class="serviceitem" type="checkbox" value="6:">
Annual Service TWO ( Sigma / Duratec / CSR )<br>
<input name="itm[]" class="serviceitem" type="checkbox" value="7:">
620 Annual Service TWO<br>
<input name="itm[]" class="serviceitem" type="checkbox" value="8:">
4 year add on (Sigma / Duratec / CSR)<br>
<input name="itm[]" class="serviceitem" type="checkbox" value="9:">
6 year add on (Sigma / Duratec / CSR)<br>
<input name="itm[]" class="serviceitem" type="checkbox" value="10:">
500 Mile Service ( K-Series )<br>
<input name="itm[]" class="serviceitem" type="checkbox" value="11:">
3000 Mile Service ( K-Series )<br>
<input name="itm[]" class="serviceitem" type="checkbox" value="12:">
6000 Mile Service ( K-Series ) <br>
<input name="itm[]" class="serviceitem" type="checkbox" value="13:">
12000 Mile Service ( K-Series )<br>
<input name="itm[]" class="serviceitem" type="checkbox" value="14:">
24000 Mile Service ( K-Series )<br>
<input name="itm[]" class="serviceitem" type="checkbox" value="15:">
Race Car Service ( All Models )<br>
<input name="itm[]" class="serviceitem" type="checkbox" value="16:">
Suzuki 160 1st Service<br>
<input name="itm[]" class="serviceitem" type="checkbox" value="17:">
Suzuki 2 Year Addon<br>
<input name="itm[]" class="serviceitem" type="checkbox" value="18:">
Suzuki 3000 Mile Service<br>
<input name="itm[]" class="serviceitem" type="checkbox" value="19:">
Suzuki 4 Year Addon<br>
<input name="itm[]" class="serviceitem" type="checkbox" value="20:">
Suzuki 6000 Mile Service<br>
<input name="itm[]" class="serviceitem" type="checkbox" value="21:">
Suzuki 6 Year Addon<br>
</div>
答案 0 :(得分:-1)
为什么不创建要插入的新变量?
将$ _POST ['itm']数组内嵌到一个新字符串中,用以下字符分隔:
$insertThis = implode(":",$_POST['itm']);
Implode将数组拆分为字符串,用第一个参数分隔每个元素,第二个参数是你的数组