|
|
|
ผมจะ insert แบบarray ทำงัยดีครับ ผมใช้ sqlsrv ช่วยแปลงเป็น sqlsrv หน่อยครับตอนนี้ผมหาได้เป็น mysql |
|
|
|
|
|
|
|
ช่วยดูให้ผมหน่อยนะครับตรงไหนผิดเพราะว่าตอนนี้ insert ไม่ออก ผมต้องการให้ insert หลายๆตัว โดยกด summit
หน้า form.php
Code (PHP)
<!-- =========================================================
* Assessment Vibharam Hospital v1
=========================================================
* Copyright 2019 Vibharam Hospital
* Coded by Vibharam Hospital Mustakeam.T
=========================================================
-->
<?php
session_start();
require_once("../include/connect.php");
function fill_unit_select_box($connect){
$output = '';
$sqlTitle = "SELECT * FROM assQtnTitle";
$qryTitle = sqlsrv_query($connect, $sqlTitle);
while ($rowTitle = sqlsrv_fetch_array($qryTitle, SQLSRV_FETCH_ASSOC)) {
$output .= '<option value="'.$rowTitle["qTitleId"].'">'.$rowTitle["qTitleName"].'</option>';
}
return $output;
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="Start your development with a Dashboard for Bootstrap 4.">
<meta name="author" content="Creative Tim">
<title>แก้ไขตั้งค่าคำถามแบบประเมินความพึ่งพอใจ - VIBHARAMLCB HOSPITAL</title>
<!-- Favicon -->
<link rel="icon" href="../assets/img/brand/favicon.png" type="image/png">
<body>
<!-- Main content -->
<div class="main-content" id="panel">
<!-- Header Navbar -->
<?php include 'header.php' ?>
<!-- Header -->
<!-- Header -->
<div class="header bg-primary pb-6">
<div class="container-fluid">
<div class="header-body">
<div class="row align-items-center py-4">
<div class="col-lg-6 col-7">
<nav aria-label="breadcrumb" class="d-none d-md-inline-block ml-md-4">
<ol class="breadcrumb breadcrumb-links breadcrumb-dark">
</ol>
</nav>
</div>
</div>
</div>
</div>
</div>
<!-- Page content -->
<div class="container-fluid mt--6">
<div class="row">
<div class="col">
<div class="card col-lg-9 center">
<!-- Card header -->
<div class="card-header border-0">
<center>
<h2 class="mb-0">
<br>
เพิ่มรายการคำถาม
</h2>
<style>
select#exampleFormControlSelect1 {
max-width: 50em;
min-width: 50em;
width: 50em !important;
}
</style>
</center>
<br>
<br>
</div>
<!-- Table Assessment -->
<div class="table-responsive">
<form id="insertQtn" method="post">
<table class="table align-items-center table-flush" id="assQtnList">
<thead class="thead-light">
<tr>
<th scope="col" width="60%"><center><h4>รายการคำถาม</h4></center></th>
<th scope="col"><center><h4>ด้านรายการประเมิน</h4></center></th>
<th scope="col"><center><h4>เผยแพร่</h4></center></th>
<th scope="col"><button type="button" name="add" class="btn btn-success add"><i class="fas fa-plus-circle"></i> เพิ่ม</button></th>
</tr>
</thead>
</table>
<br>
<br>
<center>
<!-- <button class="btn btn-success text-white btn-lg" type="submit" name="submit" id="submit" value="Insert"><i class="fas fa-save"></i> บันทึก</button>
<button class="btn btn-danger text-white btn-lg " type="reset"><i class="far fa-times-circle"></i> ยกเลิก</button> -->
<button type="submit" name="submit" class="btn btn-success btn-lg"><i class="fas fa-save"></i> บักทึก</button>
<button type="reset" class="btn btn-danger btn-lg "><i class="far fa-times-circle"></i> ยกเลิก</button>
</center>
</form>
<br>
</div>
</div>
</div>
</div>
<!-- Footer -->
<?php include 'footer.php' ?>
</div>
</div>
<!-- Argon Scripts -->
<!-- Core -->
<script src="../assets/vendor/jquery/dist/jquery.min.js"></script>
<script src="../assets/vendor/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script src="../assets/vendor/js-cookie/js.cookie.js"></script>
<script src="../assets/vendor/jquery.scrollbar/jquery.scrollbar.min.js"></script>
<script src="../assets/vendor/jquery-scroll-lock/dist/jquery-scrollLock.min.js"></script>
<!-- Optional JS -->
<script src="../assets/vendor/datatables.net/js/jquery.dataTables.min.js"></script>
<script src="../assets/vendor/datatables.net-bs4/js/dataTables.bootstrap4.min.js"></script>
<script src="../assets/vendor/datatables.net-buttons/js/dataTables.buttons.min.js"></script>
<script src="../assets/vendor/datatables.net-buttons-bs4/js/buttons.bootstrap4.min.js"></script>
<script src="../assets/vendor/datatables.net-buttons/js/buttons.html5.min.js"></script>
<script src="../assets/vendor/datatables.net-buttons/js/buttons.flash.min.js"></script>
<script src="../assets/vendor/datatables.net-buttons/js/buttons.print.min.js"></script>
<script src="../assets/vendor/datatables.net-select/js/dataTables.select.min.js"></script>
<!-- Add Insert -->
<script src="../assets/js/addInsert/bootstrap.min.js"></script>
<script src="../assets/js/addInsert/jquery.min.js"></script>
<!-- Argon JS -->
<script src="../assets/js/argon.js?v=1.1.0"></script>
<!-- Demo JS - remove this in your project -->
<script src="../assets/js/demo.min.js"></script>
<!-- Fig Js -->
<script type="text/javascript">
$(document).ready(function(){
$(document).on('click', '.add', function(){
var html = '';
html += '<tr>';
html += '<td><input type="text" name="txtList[]" class="form-control txtList" required/></td>';
html += '<td><select name="txtTitle[]" class="form-control txtTitle"><?php echo fill_unit_select_box($connect); ?></select></td>';
html += '<td>';
html += '<center>';
html += '<label class="custom-toggle">';
html += '<input type="checkbox">';
html += '<span class="custom-toggle-slider rounded-circle" data-label-off="ปิด" data-label-on="เปิด"></span>';
html += '</label>';
html += '</center>';
html += '</td>';
html += '<td><button type="button" name="remove" class="btn btn-danger remove"><i class="fas fa-times-circle"></i></button></td></tr>';
$('#assQtnList').append(html);
});
$(document).on('click', '.remove', function(){
$(this).closest('tr').remove();
});
var form_data = $(this).serialize();
$.ajax({
url:"insert/qtn.php",
method:"POST",
data:form_data,
success:function(data)
{
if(data == 'ok')
{
$('#assQtnList').find("tr:gt(0)").remove();
}
}
});
});
</script>
</body>
</html>
-------------------------------------------------------------------------------------------------------------------------------------------------------
ช่วยแปลง sqlsrv ผมแปลงแล้วไม่ออกอ่ะครับ
หน้า insert.php
Code (PHP)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>เพิ่มหัวข้อคำถาม</title>
<!-- Fonts -->
<link rel="stylesheet" href="../assets/fonts/Kanit/stylesheet.css" type="text/css" >
<style type="text/css">
div {
font-family: 'hermes-dashboard-iconsregular','kanitlight';
}
</style>
<!-- Icons -->
<link rel="stylesheet" href="../assets/vendor/nucleo/css/nucleo.css" type="text/css">
<link rel="stylesheet" href="../assets/vendor/@fortawesome/fontawesome-free/css/all.min.css" type="text/css">
<link rel="stylesheet" href="../assets/vendor/@fortawesome/fontawesome-free-5.12.0-web/css/all.min.css" type="text/css">
<!-- Argon CSS -->
<link rel="stylesheet" href="../assets/css/argon.css?v=1.1.0" type="text/css">
<!-- Color CSS -->
<link rel="stylesheet" href="../assets/css/color.css" type="text/css">
<!-- Argon CSS -->
<link rel="stylesheet" href="../assets/css/argon.css?v=1.1.0" type="text/css">
<link rel="stylesheet" href="../assets/css/argon-update.css" type="text/css">
</head>
<body>
<!-- ----------------------- php -------------------------------------- -->
<?php
session_start();
require_once("../../include/connect.php");
if(isset($_POST["txtList"]))
{
$status = "Y";
$qListId = uniqid();
foreach($_POST["txtList"] as $count){
$query = "INSERT INTO tbl_order_items
(qListId, qTitleId, qListStatus)
VALUES (:qListId, :qTitleId, :qListStatus)
";
$statement = $connect->sqlsrv_prepare($query);
$statement->sqlsrv_execute(
array(
':qListId' => $qListId,
':qTitleId' => $_POST["txtList"][$count],
':qListStatus' => $status
)
);
}
$result = $statement->fetchAll();
if(isset($result))
{
echo 'ok';
}
}
?>
</body>
</html>
Tag : PHP, Ms SQL Server 2014, Ms SQL Server 2016, Laravel Framework, CakePHP, CodeIgniter
|
|
|
|
|
|
Date :
2020-01-19 00:09:37 |
By :
mustakeam |
View :
779 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Date :
2020-01-19 00:10:33 |
By :
mustakeam |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|