|
|
|
รับค่าจาก Check Box บันทึกลง Database แต่ข้อมูลมาไม่ครบ |
|
|
|
|
|
|
|
รบกวนช่วยดู Code หน่อยค่ะ
หน้าจอ input ข้อมูล
Code (PHP)
<label >Application Installed</label>
<label>OS</label>
<input type="checkbox" class="checkbox" name="addins[]" value="Windows 7">Wins7
<input type="checkbox" class="checkbox" name="addins[]" value="Windows 10">Wins10
<label>Office</label>
<input type="checkbox" class="checkbox" name="addins[]" value="MS Office 2010">Office2010.
<input type="checkbox" class="checkbox" name="addins[]" value="MS Office 2013 Pro.">Office2013 Pro.
<input type="checkbox" class="checkbox" name="addins[]" value="MS Office 2013 Std.">Office2013 std.
<label">PDF</label>
<input type="checkbox" class="checkbox" name="addins[]" value="Adobe Acrobat Pro">Adobe Acrobat
<input type="checkbox" class="checkbox" name="addins[]" value="PDF XChange Viewer">PDF XChange Viewer
<label>Engineer</label>
<input type="checkbox" class="checkbox" name="addins[]" value="Z-TEK USB2.0">USB Driver
<input type="checkbox" class="checkbox" name="addins[]" value="Keyence USB-Serial Converter">Keyence USB
<input type="checkbox" class="checkbox" name="addins[]" value="Keyence VT Studio">VT Studio
<<input type="checkbox" class="checkbox" name="addins[]" value="GX work2">GX work2
<input type="checkbox" class="checkbox" name="addins[]" value="GT work3">GT work3
<input type="checkbox" class="checkbox" name="addins[]" value="MR Configurator2">MR Configurator2
<label>Design</label>
<input type="checkbox" class="checkbox" name="addins[]" value="G-StarCAD">G-StarCAD
<input type="checkbox" class="checkbox" name="addins[]" value="Solidwork">Solidwork
<input type="checkbox" class="checkbox" name="addins[]" value="Catia">Catia
<input type="checkbox" class="checkbox" name="addins[]" value="Space E">Space E
<label>Special</label>
<input type="checkbox" class="checkbox" name="addins[]" value="Budget Control">Budget
<input type="checkbox" class="checkbox" name="addins[]" value="Daily Report">Daily Report
<input type="checkbox" class="checkbox" name="addins[]" value="Accpac">Accpac
<input type="checkbox" class="checkbox" name="addins[]" value="OGA">OGA
<label>พื้นฐาน</label>
<input type="checkbox" class="checkbox" name="addins[]" value="Symantec Enpoint">Symantec
<input type="checkbox" class="checkbox" name="addins[]" value="TeamViewer">TeamViewer
<input type="checkbox" class="checkbox" name="addins[]" value="SmartDataEncryption">SmartDataEncryption
<input type="checkbox" class="checkbox" name="addins[]" value="Driver Printer">Driver Printer
<label>อื่นๆ</label>
<input type="text" name="addins[]">
actionมาที่หน้านี้
<?PHP
for($i=0;$i<count($_POST["addins"]);$i++){
if(trim($_POST["addins"][$i]) != ""){
$addins = $_POST["addins"][$i].",";
//echo $addins;
}
}
$strSQL = "INSERT INTO tbdevice ";
$strSQL .="(devicetypeid,devicebrand,devicemodel,devicedate,deviceamnt,deviceunit,devicesn,deviceip,devicecode,devicedesc,
userid,deptid,devicepcname,renid,devicecpu,deviceram,deviceharddisk,devicegraphic,devicecd,deviceaccessory,
licenseid,vendorid,deviceinstall,devicenetworkcard,devicesize)";
$strSQL .="VALUES ";
$strSQL .="('".$_POST["addDtype"]."','".$_POST["addbrand"]."','".$_POST["addmodel"]."','".$_POST["adddate"]."' ";
$strSQL .=",'".$_POST["addQty"]."','".$_POST["addunit"]."','".$_POST["addsn"]."','".$_POST["addip"]."' ";
$strSQL .=",'".$_POST["addcode"]."','".$_POST["adddesc"]."','".$_POST["adduser"]."','".$_POST["adddept"]."' ";
$strSQL .=",'".$_POST["addpcname"]."','".$_POST["addren"]."','".$_POST["addcpu"]."','".$_POST["addram"]."' ";
$strSQL .=",'".$_POST["addhdd"]."','".$_POST["adddisply"]."','".$_POST["addrom"]."','".$_POST["addaccessory"]."' ";
$strSQL .=",'".$_POST["addlicense"]."','".$_POST["addvendor"]."','".$addins."','".$_POST["addnetwork"]."' ";
$strSQL .=",'".$_POST["addsize"]."') ";
$objQuery = sqlsrv_query($conn,$strSQL);
if($objQuery)
{
echo "Query [".$strSQL."]";
//header("location:main.php");
}
else
{
echo " Error Save [".$strSQL."] ";
}
sqlsrv_close($conn);
?>
หน้าจอ input ข้อมูลค่ะ
action บรรทัดแรก แสดงข้อมูลจาก checkbox ครบค่ะ
แต่พอ insert จะเข้าเฉพาะ item สุดท้าย ตรงคำว่า "Symantec Endpoint"
Windows 10,MS Office 2013 Pro.,Adobe Acrobat Pro,Symantec Enpoint,
Query [INSERT INTO tbdevice (devicetypeid,devicebrand,devicemodel,devicedate,deviceamnt,deviceunit,devicesn,deviceip,devicecode,devicedesc, userid,deptid,devicepcname,renid,devicecpu,deviceram,deviceharddisk,devicegraphic,devicecd,deviceaccessory, licenseid,vendorid,deviceinstall,devicenetworkcard,devicesize)VALUES ('2','eqwewqe','TMP246M','2017-10-11' ,'1','เครื่อง','333333','123' ,'123','reqr','15','21' ,'ice','11','rwq','4GB' ,'HDD 1TB , OCZ SSD 120GB','NVIDIA GeForce 820M 2GB','DVD','rqerqw' ,'','964','Symantec Enpoint,','-' ,'14"') ]
หากอธิบายไม่เข้าใจยังไง ขอโทษด้วยค่ะ
Tag : PHP, Ms SQL Server 2008, Apache, Appserv, XAMPP, Windows
|
|
|
|
|
|
Date :
2017-10-11 13:07:11 |
By :
bonusxi |
View :
1649 |
Reply :
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เช็ค {} ในการ loop ดีๆ ครับ
Code (PHP)
<?PHP
for($i=0;$i<count($_POST["addins"]);$i++){
if(trim($_POST["addins"][$i]) != ""){
$addins = $_POST["addins"][$i].",";
//echo $addins;
$strSQL = "INSERT INTO tbdevice ";
$strSQL .="(devicetypeid,devicebrand,devicemodel,devicedate,deviceamnt,deviceunit,devicesn,deviceip,devicecode,devicedesc,
userid,deptid,devicepcname,renid,devicecpu,deviceram,deviceharddisk,devicegraphic,devicecd,deviceaccessory,
licenseid,vendorid,deviceinstall,devicenetworkcard,devicesize)";
$strSQL .="VALUES ";
$strSQL .="('".$_POST["addDtype"]."','".$_POST["addbrand"]."','".$_POST["addmodel"]."','".$_POST["adddate"]."' ";
$strSQL .=",'".$_POST["addQty"]."','".$_POST["addunit"]."','".$_POST["addsn"]."','".$_POST["addip"]."' ";
$strSQL .=",'".$_POST["addcode"]."','".$_POST["adddesc"]."','".$_POST["adduser"]."','".$_POST["adddept"]."' ";
$strSQL .=",'".$_POST["addpcname"]."','".$_POST["addren"]."','".$_POST["addcpu"]."','".$_POST["addram"]."' ";
$strSQL .=",'".$_POST["addhdd"]."','".$_POST["adddisply"]."','".$_POST["addrom"]."','".$_POST["addaccessory"]."' ";
$strSQL .=",'".$_POST["addlicense"]."','".$_POST["addvendor"]."','".$addins."','".$_POST["addnetwork"]."' ";
$strSQL .=",'".$_POST["addsize"]."') ";
$objQuery = sqlsrv_query($conn,$strSQL);
if($objQuery)
{
echo "Query [".$strSQL."]";
}
else
{
echo " Error Save [".$strSQL."] ";
}
}
}
sqlsrv_close($conn);
?>
|
|
|
|
|
Date :
2017-10-11 13:34:16 |
By :
arm8957 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
,'HDD 1TB ,
OCZ SSD 120GB',
'NVIDIA GeForce 820M 2GB',
'DVD',
'rqerqw' ,
'',
'964',
'Symantec Enpoint,'
,'-' ,
'14"
')
' ' ไม่ครบ
|
|
|
|
|
Date :
2017-10-11 14:06:36 |
By :
Hararock |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ตอบความคิดเห็นที่ : 3 เขียนโดย : bonusxi เมื่อวันที่ 2017-10-11 15:20:38
รายละเอียดของการตอบ ::
สามารถทำได้ครับ ผมไม่รุว่าค่า $_POST ออกมามีรูปแบบใด อาจจะใช้คำสั่ง implode() จากค่า $_POST เลยก็ได้โดยที่ไม่ต้อง Loop ลองปรับ แก้ไขเอาครับ
Code (PHP)
<?PHP
for($i=0;$i<count($_POST["addins"]);$i++){
if(trim($_POST["addins"][$i]) != ""){
$addThis[] = $_POST["addins"][$i];
}
}
$addins = implode(',' , $addThis);
$strSQL = "INSERT INTO tbdevice ";
$strSQL .="(devicetypeid,devicebrand,devicemodel,devicedate,deviceamnt,deviceunit,devicesn,deviceip,devicecode,devicedesc,
userid,deptid,devicepcname,renid,devicecpu,deviceram,deviceharddisk,devicegraphic,devicecd,deviceaccessory,
licenseid,vendorid,deviceinstall,devicenetworkcard,devicesize)";
$strSQL .="VALUES ";
$strSQL .="('".$_POST["addDtype"]."','".$_POST["addbrand"]."','".$_POST["addmodel"]."','".$_POST["adddate"]."' ";
$strSQL .=",'".$_POST["addQty"]."','".$_POST["addunit"]."','".$_POST["addsn"]."','".$_POST["addip"]."' ";
$strSQL .=",'".$_POST["addcode"]."','".$_POST["adddesc"]."','".$_POST["adduser"]."','".$_POST["adddept"]."' ";
$strSQL .=",'".$_POST["addpcname"]."','".$_POST["addren"]."','".$_POST["addcpu"]."','".$_POST["addram"]."' ";
$strSQL .=",'".$_POST["addhdd"]."','".$_POST["adddisply"]."','".$_POST["addrom"]."','".$_POST["addaccessory"]."' ";
$strSQL .=",'".$_POST["addlicense"]."','".$_POST["addvendor"]."','".$addins."','".$_POST["addnetwork"]."' ";
$strSQL .=",'".$_POST["addsize"]."') ";
$objQuery = sqlsrv_query($conn,$strSQL);
if($objQuery)
{
echo "Query [".$strSQL."]";
}
else
{
echo " Error Save [".$strSQL."] ";
}
sqlsrv_close($conn);
?>
|
|
|
|
|
Date :
2017-10-11 16:02:55 |
By :
arm8957 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ได้แล้วค่ะ
ขอบคุณ คุณ คนธรรมดา ไม่พิเศษ มากนะคะ
แปะโค้ดทั้งหมดให้แล้วนะคะ
ตอนแรกวางโค้ด ไม่เป็น
Code (PHP) add_device.php
<?php
include ("sqlconnect.php");
?>
<html>
<head>
</head>
<body>
<div class="container">
<form role="form" method="post" action="add_device_save.php">
<label>หมายเลขอุปกรณ์</label>
<div class="col-sm-3">
<input type="text" class="form-control" name="addcode" required>
</div>
</div>
</div>
<div class="form-group">
<div class="form-inline">
<label for="inputEmail3" class="col-sm-2">Computer Name</label>
<div class="col-sm-3">
<input type="text" class="form-control" name="addpcname" required>
</div>
</div>
</div><div class="row clearfix">
<div class="col-md-12 column">
</div>
</div>
<div class="form-group">
<div class="form-inline">
<label for="inputEmail3" class="col-sm-2">หมวดอุปกรณ์</label>
<div class="col-sm-3">
<select class="form-control" name="addDtype" required>
<option>เลือกหมวดอุปกรณ์</option>
<?php
$strSQL = "SELECT * FROM tbdevicetype";
$objQuery = sqlsrv_query($conn,$strSQL);
while($objResult = sqlsrv_fetch_array($objQuery)){
?>
<option value="<?php echo $objResult["devicetypeid"];?>"><?php echo $objResult["devicetypename"];?></option>
<?php
}
?>
</select>
</div>
</div>
</div>
<div class="form-group">
<div class="form-inline">
<label for="inputEmail3" class="col-sm-2">วันที่</label>
<div class="col-sm-3">
<input type="date" id="datepicker" class="form-control" value="<?php print(date("Y-m-d")); ?>" name="adddate" required>
</div>
</div>
</div>
<div class="row clearfix">
<div class="col-md-12 column">
</div>
</div>
<div class="form-group">
<div class="form-inline">
<label for="inputEmail3" class="col-sm-2">ยี่ห้อ</label>
<div class="col-sm-3">
<input type="text" id="datepicker" class="form-control" name="addbrand" required>
</div>
</div>
</div>
<div class="form-group">
<div class="form-inline">
<label for="inputEmail3" class="col-sm-2">รุ่น</label>
<div class="col-sm-3">
<input type="text" class="form-control" name="addmodel" required>
</div>
</div>
</div>
<div class="row clearfix">
<div class="col-md-12 column">
</div>
</div>
<div class="form-group">
<div class="form-inline">
<label for="inputEmail3" class="col-sm-2">จำนวน</label>
<div class="col-sm-3">
<input type="number" class="form-control" name="addQty" required>
</div>
</div>
</div>
<div class="form-group">
<div class="form-inline">
<label for="inputEmail3" class="col-sm-2">หน่วย</label>
<div class="col-sm-3">
<input type="text" class="form-control" placeholder="เช่น ชิ้น,อัน,เครื่อง, Pcs. " name="addunit" required>
</div>
</div>
</div>
<div class="row clearfix">
<div class="col-md-12 column">
</div>
</div>
<div class="form-group">
<div class="form-inline">
<label for="inputEmail3" class="col-sm-2">สัญญาเช่า</label>
<div class="col-sm-3">
<select class="form-control" name="addren" required>
<option>เลือกเลขที่สัญญา</option>
<?php
$strSQL = "SELECT * FROM tbRental";
$objQuery = sqlsrv_query($conn,$strSQL);
while($objResult = sqlsrv_fetch_array($objQuery)){
?>
<option value="<?php echo $objResult["renid"];?>"><?php echo $objResult["rencontractno"];?></option>
<?php
}
?>
</select>
</div>
</div>
</div>
<div class="form-group">
<div class="form-inline">
<label for="inputEmail3" class="col-sm-2">ผู้ขาย</label>
<div class="col-sm-3">
<select class="form-control" name="addvendor" required>
<option>เลือกผู้ขาย</option>
<?php
$strSQL = "SELECT * FROM tbVendor order by vendorname asc";
$objQuery = sqlsrv_query($conn,$strSQL);
while($objResult = sqlsrv_fetch_array($objQuery)){
?>
<option value="<?php echo $objResult["vendorid"];?>"><?php echo $objResult["vendorname"];?></option>
<?php
}
?>
</select>
</div>
</div>
</div>
<div class="row clearfix">
<div class="col-md-12 column">
</div>
</div>
<div class="form-group">
<div class="form-inline">
<label for="inputEmail3" class="col-sm-2">หมายเลข Serial</label>
<div class="col-sm-3">
<input type="text" class="form-control" placeholder="Serial Number" name="addsn" required>
</div>
</div>
</div>
<div class="form-group">
<div class="form-inline">
<label for="inputEmail3" class="col-sm-2">IP Address</label>
<div class="col-sm-3">
<input type="text" class="form-control" placeholder="เช่น 192.168.0.0" name="addip" required>
</div>
</div>
</div>
<div class="row clearfix">
<div class="col-md-12 column">
</div>
</div>
<div class="form-group">
<div class="form-inline">
<label for="inputEmail3" class="col-sm-2">อธิบาย Item</label>
<div class="col-sm-3">
<input type="text" class="form-control" name="adddesc" required>
</div>
</div>
</div>
<div class="form-group">
<div class="form-inline">
<label for="inputEmail3" class="col-sm-2">ผู้ใช้งาน</label>
<div class="col-sm-3">
<select class="form-control" name="adduser" required>
<option>ชื่อผู้ใช้</option>
<?php
$strSQL = "select *from tbuser ";
$objQuery = sqlsrv_query($conn,$strSQL);
while($objResult = sqlsrv_fetch_array($objQuery))
{
?>
<option value="<?php echo $objResult["userid"];?>"><?php echo $objResult["userfirstname"];?></option>
<?php
}
?>
</select>
</div>
</div>
</div>
<div class="row clearfix">
<div class="col-md-12 column">
</div>
</div>
<div class="form-group">
<div class="form-inline">
<label for="inputEmail3" class="col-sm-2">แผนก</label>
<div class="col-sm-3">
<select class="form-control" name="adddept" required>
<option>เลือกแผนก</option>
<?php
$strSQL = "SELECT * FROM tbdept";
$objQuery = sqlsrv_query($conn,$strSQL);
while($objResult = sqlsrv_fetch_array($objQuery))
{
?>
<option value="<?php echo $objResult["deptid"];?>"><?php echo $objResult["deptcode"];?></option>
<?php
}
?>
</select>
</div>
</div>
</div>
<div class="form-group">
<div class="form-inline">
<label for="inputEmail3" class="col-sm-2">Accessories</label>
<div class="col-sm-3">
<input type="text" class="form-control" name="addaccessory" required>
</div>
</div>
</div>
<div class="row clearfix">
<div class="col-md-12 column">
</div>
</div>
<div class="form-group">
<div class="form-inline">
<label for="inputEmail3" class="col-sm-2">CPU</label>
<div class="col-sm-3">
<input type="text" class="form-control" name="addcpu" required>
</div>
</div>
</div>
<div class="form-group">
<div class="form-inline">
<label for="inputEmail3" class="col-sm-2">Harddisk</label>
<div class="col-sm-3">
<input type="text" class="form-control" name="addhdd" required>
</div>
</div>
</div>
<div class="row clearfix">
<div class="col-md-12 column">
</div>
</div>
<div class="form-group">
<div class="form-inline">
<label for="inputEmail3" class="col-sm-2">RAM</label>
<div class="col-sm-3">
<input type="text" class="form-control" name="addram" required>
</div>
</div>
</div>
<div class="form-group">
<div class="form-inline">
<label for="inputEmail3" class="col-sm-2">CD ROM</label>
<div class="col-sm-3">
<input type="text" class="form-control" name="addrom" required>
</div>
</div>
</div>
<div class="row clearfix">
<div class="col-md-12 column">
</div>
</div>
<div class="form-group">
<div class="form-inline">
<label for="inputEmail3" class="col-sm-2">Graphic</label>
<div class="col-sm-3">
<input type="text" class="form-control" name="adddisply" required>
</div>
</div>
</div>
<div class="form-group">
<div class="form-inline">
<label for="inputEmail3" class="col-sm-2">Network Card</label>
<div class="col-sm-3">
<input type="text" class="form-control" name="addnetwork" required>
</div>
</div>
</div>
<div class="row clearfix">
<div class="col-md-12 column">
</div>
</div>
<div class="form-group">
<div class="form-inline">
<label for="inputEmail3" class="col-sm-2">Size</label>
<div class="col-sm-3">
<input type="text" class="form-control" name="addsize" required>
</div>
</div>
</div>
<div class="form-group">
<div class="form-inline">
<label for="inputEmail3" class="col-sm-2">ราคา</label>
<div class="col-sm-3">
<input type="text" class="form-control" name="addprice" required>
</div>
</div>
</div> <div class="row clearfix">
<div class="col-md-12 column">
</div>
</div>
<div class="form-group">
<div class="form-inline">
<label for="inputEmail3" class="col-sm-2">Application Installed</label>
<div class="col-sm-10 ridge">
<div class="col-sm-12" >
<label for="inputEmail3" class="col-sm-1">OS</label><br>
<div class="col-sm-12" >
<input type="checkbox" class="checkbox" name="addins[]" value="Windows 7">Wins7
<input type="checkbox" class="checkbox" name="addins[]" value="Windows 10">Wins10
</div>
</div>
<div class="row clearfix">
<div class="col-md-12 column">
</div>
</div>
<div class="col-sm-12" >
<label for="inputEmail3" class="col-sm-1">Office</label>
<div class="col-sm-12" >
<input type="checkbox" class="checkbox" name="addins[]" value="MS Office 2010">Office2010.
<input type="checkbox" class="checkbox" name="addins[]" value="MS Office 2013 Pro.">Office2013 Pro.
<input type="checkbox" class="checkbox" name="addins[]" value="MS Office 2013 Std.">Office2013 std.
</div>
</div>
<div class="row clearfix">
<div class="col-md-12 column">
</div>
</div>
<div class="col-sm-12" >
<label for="inputEmail3" class="col-sm-1">PDF</label>
<div class="col-sm-12" >
<input type="checkbox" class="checkbox" name="addins[]" value="Adobe Acrobat Pro">Adobe Acrobat
<input type="checkbox" class="checkbox" name="addins[]" value="PDF XChange Viewer">PDF XChange Viewer
</div>
</div>
<div class="row clearfix">
<div class="col-md-12 column">
</div>
</div>
<div class="col-sm-12" >
<label for="inputEmail3" class="col-sm-2">Maintenace</label>
<div class="col-sm-12" >
<input type="checkbox" class="checkbox" name="addins[]" value="Z-TEK USB2.0">USB Driver
<input type="checkbox" class="checkbox" name="addins[]" value="Keyence USB-Serial Converter">Keyence USB
<input type="checkbox" class="checkbox" name="addins[]" value="Keyence VT Studio">VT Studio
<input type="checkbox" class="checkbox" name="addins[]" value="Keyence KV Studio">KV Studio
<input type="checkbox" class="checkbox" name="addins[]" value="GX work2">GX work2
<input type="checkbox" class="checkbox" name="addins[]" value="GT work3">GT work3
<input type="checkbox" class="checkbox" name="addins[]" value="MR Configurator2">MR Configurator2
</div>
</div>
<div class="row clearfix">
<div class="col-md-12 column">
</div>
</div>
<div class="col-sm-12" >
<label for="inputEmail3" class="col-sm-2">Design</label>
<div class="col-sm-12" >
<input type="checkbox" class="checkbox" name="addins[]" value="G-StarCAD">G-StarCAD
<input type="checkbox" class="checkbox" name="addins[]" value="Solidwork">Solidwork
<input type="checkbox" class="checkbox" name="addins[]" value="Catia">Catia
<input type="checkbox" class="checkbox" name="addins[]" value="Space E">Space E
</div>
</div>
<div class="row clearfix">
<div class="col-md-12 column">
</div>
</div>
<div class="col-sm-12" >
<label for="inputEmail3" class="col-sm-2">KPC</label>
<div class="col-sm-12" >
<input type="checkbox" class="checkbox" name="addins[]" value="Budget Control">Budget
<input type="checkbox" class="checkbox" name="addins[]" value="Daily Report">Daily Report
<input type="checkbox" class="checkbox" name="addins[]" value="Accpac">Accpac
<input type="checkbox" class="checkbox" name="addins[]" value="OGA">OGA
</div>
</div>
<div class="row clearfix">
<div class="col-md-12 column">
</div>
</div>
<div class="col-sm-12" >
<label for="inputEmail3" class="col-sm-2">พื้นฐาน</label>
<div class="col-sm-12" >
<input type="checkbox" class="checkbox" name="addins[]" value="Symantec Enpoint">Symantec
<input type="checkbox" class="checkbox" name="addins[]" value="TeamViewer">TeamViewer
<input type="checkbox" class="checkbox" name="addins[]" value="SmartDataEncryption">SmartDataEncryption
<input type="checkbox" class="checkbox" name="addins[]" value="Driver Printer">Driver Printer
</div>
</div>
<div class="row clearfix">
<div class="col-md-12 column">
</div>
</div>
<div class="col-sm-12" >
<label for="inputEmail3" class="col-sm-2">ลูกค้า</label>
<div class="col-sm-12" >
<input type="checkbox" class="checkbox" name="addins[]" value="VPN Mitsubishi">VPN Mitsubishi
<input type="checkbox" class="checkbox" name="addins[]" value="VPN Toyota">VPN Toyota
</div>
</div>
<div class="row clearfix">
<div class="col-md-12 column">
</div>
</div>
<div class="col-sm-12" >
<label for="inputEmail3" class="col-sm-2">IT</label>
<div class="col-sm-12" >
<input type="checkbox" class="checkbox" name="addins[]" value="Visual Studio 2015">Visual Studio 2015
<input type="checkbox" class="checkbox" name="addins[]" value="VMware vSphere">VMware vSphere
<input type="checkbox" class="checkbox" name="addins[]" value="Crystal Report">Crystal Report
</div>
</div>
<div class="row clearfix">
<div class="col-md-12 column">
</div>
</div>
<div class="col-sm-12" >
<label for="inputEmail3" class="col-sm-2">อื่นๆ</label>
<div class="col-sm-12" >
<input type="text" class="form-control" name="addins[]">
</div>
</div>
<div class="row clearfix">
<div class="col-md-12 column">
</div>
</div>
</div>
</div>
</div>
<div class="row clearfix">
<div class="col-md-12 column">
</div>
</div>
<div align="left">
<button type="submit" class="btn btn-success"><span class="glyphicon glyphicon-plus"></span>บันทึก</button>
<div class="col-md-1"></div>
<a href="main.php"><button type="button" class="btn btn-danger"><span class="glyphicon glyphicon-minus"></span>ยกเลิก</button></a>
</div>
</form>
</div>
</body>
</html>
Code (PHP) add_device_save.php
<?php
session_start();
require ('sqlconnect.php');
if($_SESSION['userid'] == ""){
header("Content-type: text/html; charset=utf-8");
echo"<script language='JavaScript' >";
echo"alert('กรุณากรอกข้อมูลเพื่อเข้าสู่ระบบ');";
echo"</script>";
exit();
}
?>
<?PHP
for($i=0;$i<count($_POST["addins"]);$i++){
if(trim($_POST["addins"][$i]) != ""){
$addThis[] = $_POST["addins"][$i];
$addins = $_POST["addins"][$i].",";
}
}
$addins = implode(',' , $addThis);
$strSQL = "INSERT INTO tbdevice ";
$strSQL .="(devicetypeid,devicebrand,devicemodel,devicedate,
deviceamnt,deviceunit,devicesn,deviceip,
devicecode,devicedesc,userid,deptid,
devicepcname,renid,devicecpu,deviceram,
deviceharddisk,devicegraphic,devicecd,deviceaccessory,
deviceprice,vendorid,deviceinstall,devicenetworkcard,devicesize)";
$strSQL .="VALUES ";
$strSQL .="('".$_POST["addDtype"]."','".$_POST["addbrand"]."','".$_POST["addmodel"]."','".$_POST["adddate"]."' ";
$strSQL .=",'".$_POST["addQty"]."','".$_POST["addunit"]."','".$_POST["addsn"]."','".$_POST["addip"]."' ";
$strSQL .=",'".$_POST["addcode"]."','".$_POST["adddesc"]."','".$_POST["adduser"]."','".$_POST["adddept"]."' ";
$strSQL .=",'".$_POST["addpcname"]."','".$_POST["addren"]."','".$_POST["addcpu"]."','".$_POST["addram"]."' ";
$strSQL .=",'".$_POST["addhdd"]."','".$_POST["adddisply"]."','".$_POST["addrom"]."','".$_POST["addaccessory"]."' ";
$strSQL .=",'".$_POST["addprice"]."','".$_POST["addvendor"]."','".$addins."','".$_POST["addnetwork"]."','".$_POST["addsize"]."') ";
$objQuery = sqlsrv_query($conn,$strSQL);
if($objQuery)
{
header("location:main.php");
}
else
{
echo " Error Save [".$strSQL."] ";
}
sqlsrv_close($conn);
?>
|
|
|
|
|
Date :
2017-10-11 17:04:55 |
By :
bonusxi |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|