 |
|
Code (PHP) work_edit.php
<?php
include ("chksession.php");
include("config.inc.php");
if(isset($_GET['reservation_id'])){
$reservation_id = $_GET['reservation_id'];
}else{
$reservation_id = "";#default value
}
//$sql1 = "select reservation_id, ceremony_id, DATE_FORMAT(begin_datetime, '%Y-%m-%dT%H:%i') AS begin_datetime, DATE_FORMAT(end_datetime, '%Y-%m-%dT%H:%i') AS end_datetime, quantity, yom_id, robe, remark from `reservation` where reservation_id='$reservation_id'";
$sql1 = "select reservation_id, ceremony_id, begin_date, DATE_FORMAT(begin_time, '%H:%i') as begin_time, end_date, DATE_FORMAT(end_time, '%H:%i') as end_time, quantity, yom_id, robe, go, remark from `reservation` where reservation_id='$reservation_id'";
$result1 = mysqli_query($conn,$sql1) or die(mysqli_error($conn));
$row1 = mysqli_fetch_array($result1);
$ceremony_id = $row1['ceremony_id'];
//$begin_datetime = $row1['begin_datetime'];
//$end_datetime = $row1['end_datetime'];
$start_date = $row1['begin_date'];
$start_time = $row1['begin_time'];
$end_date = $row1['end_date'];
$end_time = $row1['end_time'];
$quantity = $row1['quantity'];
$yom_id = $row1['yom_id'];
$robe = $row1['robe'];
$go = $row1['go'];
$remark = $row1['remark'];
//$icount3 = count($_SESSION['checked9']);
//echo $icount3."<br>";
//echo "start_date = $start_date <br>";
//echo "end_date = $end_date <br>";
mysqli_close($conn);
?>
<HTML>
<HEAD>
<TITLE>แก้ไขข้อมูลกิจนิมนต์</TITLE>
<script src="./scripts/jquery-1.6.min.js" type="text/javascript" charset="utf-8"></script>
<script>
var $jq16 = jQuery.noConflict();
//alert($jq16.fn.jquery);
</script>
<script src="./scripts/jquery-ui.min.js" type="text/javascript" charset="utf-8"></script>
<script src="./scripts/jquery.ui.datepicker-th.js" type="text/javascript" charset="utf-8"></script>
<script src="./scripts/jquery.ui.datetimepicker.js" type="text/javascript" charset="utf-8"></script>
<script src="./scripts/jquery.ui.datepicker.ext.be.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
$jq16(document).ready(function(){
//alert($jq16.fn.jquery);
//$jq16('#start_date').datepicker();
//var myDate = new Date();
//$jq16('#start_date').datepicker();
//$jq16('#start_date').datepicker('setDate', myDate);
$jq16('#start_date').datepicker({
dateFormat: 'yy-mm-dd',
monthNames: ['มกราคม', 'กุมภาพันธ์', 'มีนาคม', 'เมษายน', 'พฤษภาคม', 'มิถุนายน', 'กรกฎาคม', 'สิงหาคม', 'กันยายน', 'ตุลาคม', 'พฤศจิกายน', 'ธันวาคม'],
dayNamesMin: ['อา.', 'จ.', 'อ.', 'พ.', 'พฤ.', 'ศ.', 'ส.'],
timeText: 'เวลา',
hourText: 'ชั่วโมง',
minuteText: 'นาที',
currentText: 'เวลาปัจจุบัน',
closeText: 'ตกลง',
isBE:true
});
//$jq16('#end_date').datepicker();
$jq16('#end_date').datepicker({
dateFormat: 'yy-mm-dd',
monthNames: ['มกราคม', 'กุมภาพันธ์', 'มีนาคม', 'เมษายน', 'พฤษภาคม', 'มิถุนายน', 'กรกฎาคม', 'สิงหาคม', 'กันยายน', 'ตุลาคม', 'พฤศจิกายน', 'ธันวาคม'],
dayNamesMin: ['อา.', 'จ.', 'อ.', 'พ.', 'พฤ.', 'ศ.', 'ส.'],
timeText: 'เวลา',
hourText: 'ชั่วโมง',
minuteText: 'นาที',
currentText: 'เวลาปัจจุบัน',
closeText: 'ตกลง',
isBE:true
});
//$jq16('#end_date').datepicker('setDate','<?php //echo $end_date;?>');
//$jq16('#end_date').datepicker('setDate','2018-12-04');
//$jq16('#end_date').datepicker({defaultDate: new Date (dbDate)});
$jq16('#start_time').timepicker({
//dateFormat: 'yy-mm-dd',
//isBE:true
timeText: 'เวลา',
hourText: 'ชั่วโมง',
minuteText: 'นาที',
currentText: 'เวลาปัจจุบัน',
closeText: 'ตกลง'
});
$jq16("#end_time").timepicker({
//changeMonth: false,
//changeYear: true,
//showButtonPanel: true,
//dateFormat: 'dd/mm/yy',
//isBE: true,
//autoConversionField: true
timeText: 'เวลา',
hourText: 'ชั่วโมง',
minuteText: 'นาที',
currentText: 'เวลาปัจจุบัน',
closeText: 'ตกลง'
});
});
</script>
<script type="text/javascript">
$jq16(document).ready(function(){
//alert($jq16.fn.jquery);
//var myDate = new Date(2018,12,04);
//$jq16('#start_date').datepicker('setDate', '04/12/2018');
//alert($.fn.jquery);
var start_date="<?php echo $start_date;?>";
//alert(start_date);
var end_date ="<?php echo $end_date;?>";
//alert(end_date);
//$jq16('#end_date').datepicker();
$jq16('#start_date').datepicker('setDate',start_date);
$jq16('#end_date').datepicker('setDate',end_date);
//var pars = $jq16( "#start_date" ).datepicker( "getDate" );
//alert(pars);
//var pars = new Date( $('#start_date').val() );
//alert(pars.getFullYear() + "-" + (pars.getMonth()+ 1) + "-" + pars.getDate());
//var date = $jq16('#start_date').datepicker({dateFormat: 'yyyy-mm-dd'}).val();
//alert(date);
});
</script>
<!--<script type="text/javascript">
$(function() {
alert($jq16.fn.jquery);
$('form').submit(function(){
$(this).submit();
alert($jq16.fn.jquery);
var pars = $jq16('#start_date').datepicker({dateFormat: 'yyyy-mm-dd'}).val();
//var pars = $jq16( "#start_date" ).datepicker( "getDate" );
alert(pars);
//var pars = new Date( $('#start_date').val() );
//alert(pars);
//var newpars = pars.getFullYear() + "-" + (pars.getMonth()+ 1) + "-" + pars.getDate();
$.ajax({
url:'work_edit2.php',
type:'post',
data:pars,
success:function(result){
$("#div1").html(result);
},
error: function(jqxhr, status, exception) {
alert('Exception:'+ exception);
}
});
});
});
</script>-->
<link rel="stylesheet" href="./css/redmond/jquery-ui.css" type="text/css"/>
<!--<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">-->
<script type="text/javascript" src="js/jquery-1.11.2.min.js"></script>
<script>
var $jq1112 = jQuery.noConflict();
//alert($jq1112.fn.jquery);
</script>
<script type="text/javascript">
$jq1112(document).ready(function() {
var get_reservation_id ="<?php echo $reservation_id;?>";
//alert(get_reservation_id);
$jq1112("#results" ).load( "workedit_fetch_pages.php",{reservation_id: get_reservation_id}); //load initial records
//executes code below when user click on pagination links
$jq1112("#results").on( "click", ".pagination a", function (e){
e.preventDefault();
$jq1112(".loading-div").show(); //show loading element
var page = $(this).attr("data-page"); //get page number from link
$jq1112("#results").load("workedit_fetch_pages.php",{"page":page, reservation_id: get_reservation_id}, function(){ //get content from PHP page
$jq1112(".loading-div").hide(); //once done, hide loading element
});
});
$jq1112("#results").on( "click", ".tick", function (e){
e.preventDefault();
$jq1112(".loading-div").show(); //show loading element
var page = $jq1112(this).attr("data-page"); //get page number from link
$jq1112("#results").load("workedit_fetch_pages.php",{"page":page, reservation_id: get_reservation_id}, function(){ //get content from PHP page
$jq1112(".loading-div").hide(); //once done, hide loading element
});
});
});
</script>
<script>
$jq1112(function() {
$jq1112('form').submit(function(){
$jq1112(this).submit();
var pars = "type=destroy";
$jq1112.ajax({
url:'workedit_ajax.php',
type:'get',
data:pars,
success:function(result){
$jq1112("#div1").html(result);
},
error: function(jqxhr, status, exception) {
alert('Exception:'+ exception);
}
});
});
});
</script>
<script>
$jq1112(function(){
$jq1112('#div2').click(function(){
var pars = "type=reset";
//alert(pars);
$jq1112.ajax({
url:'workedit_ajax.php',
type:'get',
data:pars,
success:function(result){
$jq1112("#div1").html(result);
},
error: function(jqxhr, status, exception) {
alert('Exception:'+ exception);
}
});
});
});
</script>
<script>
$jq1112(document).ready(function(){
$jq1112('input.radio-ceremony_id').click(function(){
$jq1112("#txtother").prop('disabled', true);
if($jq1112(this).attr('id') == 'อื่นๆ'){
$jq1112("#txtother").prop('disabled', false);
}
});
});
</script>
<script type="text/javascript">
$jq1112(document).ready(function(){
alert($jq1112.fn.jquery);
$jq1112("#frmWorkEdit").submit(function(e){
e.preventDefault();
var start_date = $jq16('#start_date').datepicker({dateFormat: 'yyyy-mm-dd'}).val();
alert('start_date =' + start_date);
var pars = "start_date=" + start_date;
$jq1112.ajax({
url:'workedit_ajax.php',
type:'post',
data:pars,
success:function(result){
//$jq1112("#div1").html(result);
if(result == 'ok'){
alert('All good. Everything saved!(start_date).');
}else{
alert('sumething went wrong');
}
},
error: function(jqxhr, status, exception) {
alert('Exception:'+ exception);
}
});
var end_date = $jq16('#end_date').datepicker({dateFormat: 'yyyy-mm-dd'}).val();
alert('end_date =' + end_date);
var pars = "end_date=" + end_date;
$jq1112.ajax({
url:'workedit_ajax.php',
type:'post',
data:pars,
success:function(result){
//$jq1112("#div1").html(result);
if(result == 'ok'){
alert('All good. Everything saved!(end_date).');
}else{
alert('sumething went wrong');
}
},
error: function(jqxhr, status, exception) {
alert('Exception:'+ exception);
}
});
});
});
</script>
<style>
body,td,th {
font-family: Georgia, "Times New Roman", Times, serif;
color: #333;
}
.contents{
margin: 20px;
padding: 20px;
list-style: none;
background: #F9F9F9;
border: 1px solid #ddd;
border-radius: 5px;
}
.contents li{
margin-bottom: 10px;
}
.loading-div{
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.56);
z-index: 999;
display:none;
}
.loading-div img {
margin-top: 20%;
margin-left: 50%;
}
/* Pagination style */
.pagination{margin:0;padding:0;}
.pagination li{
display: inline;
padding: 6px 10px 6px 10px;
border: 1px solid #ddd;
margin-right: -1px;
font: 15px/20px Arial, Helvetica, sans-serif;
background: #FFFFFF;
box-shadow: inset 1px 1px 5px #F4F4F4;
}
.pagination li a{
text-decoration:none;
color: rgb(89, 141, 235);
}
.pagination li.first {
border-radius: 5px 0px 0px 5px;
}
.pagination li.last {
border-radius: 0px 5px 5px 0px;
}
.pagination li:hover{
background: #CFF;
}
.pagination li.active{
background: #F0F0F0;
color: #333;
}
.btn_submit{
background-color: #4CAF50;
color: white;
} /* Green */
.btn_reset{
background-color: #f44336;
color: white;
} /* Red */
.a_link{
background-color: orange;
color: white;
padding: 14px 25px;
text-align: center;
text-decoration: none;
display: inline-block;
}
</style>
</HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<BODY>
<div id="div2"><a href='workmain.php'class='a_link' >หน้าหลักจัดการข้อมูลกิจนิมนต์ </a></div>
<hr>
<FORM id="frmWorkEdit" METHOD="POST" ACTION="work_edit2.php">
เลขที่ : <?php echo $reservation_id;?><br>
<!--วันเวลาเริ่ม :
<input type="datetime-local" name="start_time" value=<?php //echo $begin_datetime ;?>>
วันเวลาจบ :
<input type="datetime-local" name="end_time" value=<?php //echo $end_datetime ;?>><br>-->
วันเริ่มงาน :
<!--<input type="datetime-local" name="start_date" required />-->
<!--<input type="text" id="start_date" name="start_date" VALUE="<?php //echo $start_date;?>" required />-->
<input type="text" id="start_date" name="start_date" required />
เวลาเริ่มออกเดินทาง :
<input type="text" id="start_time" name="start_time" VALUE="<?php echo $start_time;?>" required />
<!--<input type="text" id="start_time" name="start_time" required />-->
<p>วันเลิกงาน :
<!--<input type="datetime-local" name="end_date"><br>-->
<!--<input type="text" id="end_date" name="end_date" VALUE="<?php //echo $end_date;?>" />-->
<input type="text" id="end_date" name="end_date" />
เวลาเลิกงาน :
<input type="text" id="end_time" name='end_time' VALUE="<?php echo $end_time;?>" />
<!--<input type="text" id="end_time" name='end_time' />-->
</p>
<br>
โปรดเลือกงาน :
<?php
include("config.inc.php");
$strSQL = "SELECT * FROM ceremony ORDER BY ceremony_id ASC";
$objQuery = mysqli_query($conn,$strSQL);
while($objResult = mysqli_fetch_array($objQuery)){
if($ceremony_id == $objResult["ceremony_id"]){
$checked = "checked";
}
else{
$checked = "";
}
?>
<input id="<?php echo $objResult["ceremony_name"];?>" name="ceremony_id" class="radio-ceremony_id" type="radio" value="<?php echo $objResult["ceremony_id"];?>"<?php echo $checked;?>><?php echo $objResult["ceremony_name"];?></option>
<?php
}
mysqli_close($conn);
?>
<input ID="txtother" name="txtother" type="text" VALUE=<?=$remark?>>
<br>
นิมนต์พระ :
<input ID="quantity" name="quantity" type="text" VALUE=<?=$quantity?>>รูป<br>
การห่มผ้า:
<?php
include("config.inc.php");
$strSQL = "SELECT * FROM robe ORDER BY robe_id ASC";
$objQuery = mysqli_query($conn,$strSQL);
while($objResult = mysqli_fetch_array($objQuery)){
if($robe == $objResult["robe_id"]){
$checked = "checked";
}
else{
$checked = "";
}
?>
<input name="robe" type="radio" value="<?php echo $objResult["robe_id"];?>"<?php echo $checked;?>><?php echo $objResult["robe_name"];?></option>
<?php
}
mysqli_close($conn);
?>
<br>
โยม:
<select name="yom">
<?php
include("config.inc.php");
$strSQL = "SELECT * FROM yom ORDER BY yom_id ASC";
$objQuery = mysqli_query($conn,$strSQL);
while($objResult = mysqli_fetch_array($objQuery))
{
if($yom_id == $objResult["yom_id"])
{
$sel = "selected";
}
else
{
$sel = "";
}
?>
<option value="<?php echo $objResult["yom_id"];?>"<?php echo $sel;?>><?php echo $objResult["yom_id"]." - ".$objResult["yom_name"];?></option>
<?php
}
mysqli_close($conn);
?>
</select><br>
รายชื่อพระภิกษุ :<br>
<div class="loading-div"><img src="ajax-loader.gif" ></div>
<div id="results"><!-- content will be loaded here --></div>
<div id="div1"></div>
<?php
//$icount3 = count($_SESSION['checked9']);
//echo $icount3."<br>";
//$icount3 = count($_SESSION['checked9']);
//echo "\$icount3 = $icount3 <br>";
?>
<select name="go">
<?php
include("config.inc.php");
$strSQL = "SELECT * FROM go ORDER BY id ASC";
$objQuery = mysqli_query($conn,$strSQL);
while($objResult = mysqli_fetch_array($objQuery)){
?>
<option value="<?php echo $objResult['id'];?>"<?php if ($go == $objResult['id']){echo 'selected="selected"';}?>><?php echo $objResult["name"];?></option>
<?php
}
mysqli_close($conn);
?>
</select><br>
<P><INPUT id="submit" name="submit" TYPE="submit" class='btn_submit' VALUE="บันทึก"><INPUT TYPE="reset" class='btn_reset' VALUE="ล้าง"></P>
<INPUT type="hidden" name="reservation_id" value="<?php echo $reservation_id;?>">
</FORM>
<script type="text/javascript">
$jq1112(document).ready(function(){
alert($jq1112.fn.jquery);
$jq1112('#frmWorkEdit').submit(function(e){
//e.preventDefault();
var pars = "type=countcb";
alert(pars);
$jq1112.ajax({
async:true,
url:'workedit_ajax.php',
type:'get',
data:pars,
success:function(result){
//$("#div1").html(result);
//var tickchecked = $('.tick:checked').length;
//var tickchecked = result;
//var tickchecked ="<?//=count($_SESSION['checked9']);?>";
//alert('tickchecked = ' + tickchecked);
//var cbchecked = '';
//var cbchecked = $('.tick').is(':checked').length;
//alert('cbchecked = ' + cbchecked);
//var sum = cbchecked + tickchecked;
//var sum = tickchecked;
//alert('sum = '+ sum);
var quantity = $jq1112('#quantity').val();
var iquantity = parseInt(quantity);
alert('iquantity = ' + iquantity);
var iresult = parseInt(result);
alert('iresult = ' + iresult);
if (iresult > iquantity) {
alert('iresult > iquantity: คุณติ๊กเลือกพระมากกว่าจำนวนพระที่นิมนต์ กรุณาติ๊กเลือกออกจากหน้าแก้ไข');
} else if (iresult < iquantity) {
//alert(result < quantity);
//alert('iquantity = ' + iquantity);
//alert('iresult = ' + iresult);
alert('iresult < iquantity: คุณติ๊กเลือกพระน้อยกว่าจำนวนพระที่นิมนต์ กรุณาติ๊กเลือกเพิ่มจากหน้าแก้ไข');
} else if (iresult = iquantity) {
alert('iresult = iquantity:คุณติ๊กเลือกพระเท่ากับจำนวนพระที่นิมนต์');
} else {
alert('no case');
}
},
error: function(jqxhr, status, exception) {
alert('Exception:'+ exception);
}
});
});
});
</script>
</BODY>
</HTML>
Code (PHP)work_edit2.php
<HTML>
<HEAD>
<TITLE>monk Edit2</TITLE>
</HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<BODY>
<?php
include("chksession.php");
include("config.inc.php");
include("functions.php");
include("checkflag1.php");
include("checkflag2.php");
$reservation_id = $_POST['reservation_id'];
$ceremony_id = $_POST['ceremony_id'];
$start_date = $_SESSION['start_date'];
$start_time = $_POST['start_time'];
//$end_date = $_POST['end_date'];
$end_date = $_SESSION['end_date'];
$end_time = $_POST['end_time'];
$quantity = $_POST['quantity'];
$yom = $_POST['yom'];
$robe = $_POST['robe'];
//$monks = $_POST['monks'];
$monks = $_SESSION['checked9'];
function cmp($a, $b){
if ($a == $b){
return 0;
}
return ($a < $b) ? -1 : 1;
}
//print_r ($monks);
//echo "<br>";
//$monksSort = asort(array_values($monks));
//asort($monks);
usort($monks, "cmp");
//print_r ($monks);
//echo "<br>";
$go = $_POST['go'];
$remark = $_POST['txtother'];
if($reservation_id=="" or $start_date=="" or $ceremony_id=="" or $quantity==""){
echo "Fill in not complete";
echo "\$reservation_id = $reservation_id";
echo "\$start_date = $start_date";
echo "\$ceremony_id = $ceremony_id";
echo "\$quantity = $quantity";
echo "<a href='workmain.php'>กลับหน้าหลัก</a>";
exit;
}
/**if(isset($_POST['start_date'])){
$start_date = $_POST['start_date'];
}else{
$start_date = "";#default value
}
if(isset($_POST['end_date'])){
$end_date = $_POST['end_date'];
}else{
$end_date = "";#default value
}**/
//mysqli_begin_transaction($conn, MYSQLI_TRANS_START_READ_WRITE);
// Set autocommit to off
mysqli_autocommit($conn,FALSE);
$sql1 = "update reservation set ceremony_id='$ceremony_id', begin_date='$start_date', begin_time='$start_time', end_date='$end_date', end_time='$end_time', quantity='$quantity', yom_id='$yom', robe='$robe', go='$go', remark='$remark' where reservation_id='$reservation_id'";
//echo "$sql1<br>";
$result1 = mysqli_query($conn,$sql1) or die(mysqli_error($conn));
//var_dump($result1);
//echo "<br>";
if(isset($_POST['reservation_id'])){
$reservation_id = $_POST['reservation_id'];
}else{
$reservation_id = "";#default value
}
//echo "reservation_id = $reservation_id<br>";
$sql2 = "select monk_id from reserved where reservation_id = $reservation_id";
//echo "$sql2<br>";
$result2 = select($sql2);
//print_r($results1);
/*foreach ($monk_id as $r){
echo "row2 = $r<br>";
}*/
//natcasesort($result2);
$icount1 = count($result2);
$icount2 = count($monks);
//echo "icount2 = $icount2 <br>";
if ($icount2 >= $icount1) {
//echo "\$icount2 >= \$icount1";
$j = 0;
while ($j < $icount2){
$rs1 = $result2[$j];
$r1[] = $rs1['monk_id'];
//natcasesort($r1);
usort($r1,"cmp");
//print_r($r1);
//$sql3 ="select count(*) from reserved where reservation_id='$reservation_id' and monk_id='$r1[$j]'";
$sql3 ="select count(*) from reserved where reservation_id='$reservation_id' and monk_id='$monks[$j]'";
//echo "$sql3<br>";
$result3 = mysqli_query($conn,$sql3) or die (mysqli_error($conn));
//var_dump($result3);
//echo "<br>";
while($data = mysqli_fetch_array($result3)){
$result = $data["count(*)"];
//echo "result = $result <br>";
}
if ($result > 0){
//$sql4 = "update reserved set monk_id='$monks[$j]' where reservation_id='$reservation_id' and monk_id='$r1[$j]'";
$sql4 = "update reserved set monk_id='$monks[$j]' where reservation_id='$reservation_id' and monk_id='$monks[$j]'";
//echo "$sql4<br>";
$result4 = mysqli_query($conn,$sql4) or die(mysqli_error($conn));
if(checkflag1()){
for($l = 1; $l <= 5; $l++){
//if(checkflag($l)){
//$r4 = flag_edit($l);
//$count = count($r4);
$count = count($monks);
if($count != 0){
//foreach($r4 as $v){
//echo "\$v = $v<br>";
if(checkflag2($l)){
//$sql4 = "update monks set flag = 1 where monk_id = $v";
$sql9 = "update monks set flag = 1 where monk_id = $monks[$j]";
//echo $sql4."<br>";
$sqlquery9 = mysqli_query($conn, $sql9) or die ("ไม่สามารถอัพเดตข้อมูลได้ กรุณาตรวจสอบข้อมูลอีกครั้ง".mysqli_error($conn));
}else{
echo "workedit: checkflag2 monk_id = $monks[$j] can't update flag = 1<br>";
}
//}
}
//}else{
// echo "can't update flag = 1<br>";
//}
}
}else{
echo "workedit: checkflag1 can't update flag = 1<br>";
}
}elseif ($result <= 0) {
$sql5 ="insert into reserved values ";
$sql5 .="('".$reservation_id."','".$monks[$j]."')";
//echo "$sql5<br>";
$result5 = mysqli_query($conn,$sql5) or die(mysqli_error($conn));
if(checkflag1()){
for($l = 1; $l <= 5; $l++){
//if(checkflag($l)){
//$r4 = flag_edit($l);
//$count = count($r4);
$count = count($monks);
if($count != 0){
//foreach($r4 as $v){
//echo "\$v = $v<br>";
if(checkflag2($l)){
//$sql4 = "update monks set flag = 1 where monk_id = $v";
$sql10 = "update monks set flag = 1 where monk_id = $monks[$j]";
//echo $sql4."<br>";
$sqlquery10 = mysqli_query($conn, $sql10) or die ("ไม่สามารถอัพเดตข้อมูลได้ กรุณาตรวจสอบข้อมูลอีกครั้ง".mysqli_error($conn));
}else{
echo "can't update flag = 1<br>";
}
//}
}
//}else{
// echo "can't update flag = 1<br>";
//}
}
}else{
echo "can't update flag = 1<br>";
}
}
$j++;
//echo "j = $j <br>";
}
}elseif ($icount2 < $icount1) {
//echo "\$icount2=$icount2 < \$icount1=$icount1";
$j = 0;
while ($j < $icount1){
$rs2 = $result2[$j];
$r2[] = $rs2['monk_id'];
//natcasesort($r1);
//usort($r1,"cmp");
//print_r($r1);
$sql8 = "update monks set flag = 0 where monk_id = '$r2[$j]'";
//echo "$sql8<br>";
$result8 = mysqli_query($conn,$sql8) or die (mysqli_error($conn));
$j++;
}
$sql6 = "DELETE FROM `reserved` WHERE reservation_id=$reservation_id";
//echo "$sql6<br>";
$result6 = mysqli_query($conn,$sql6) or die(mysqli_error($conn));
//var_dump($result6);
//echo "<br>";
if ($icount2 == 0){
goto normal_end;
}
for($k=0;$k<=count($monks)-1;$k++){
$sql7 ="insert into reserved values ";
$sql7 .="(".$reservation_id.",".$monks[$k].")";
//echo "$sql7<br>";
$result7 = mysqli_query($conn,$sql7) or die(mysqli_error($conn));
//var_dump($result7);
//echo "<br>";
if(checkflag1()){
for($l = 1; $l <= 5; $l++){
//if(checkflag($l)){
//$r4 = flag_edit($l);
//$count = count($r4);
$count = count($monks);
if($count != 0){
//foreach($r4 as $v){
//echo "\$v = $v<br>";
if(checkflag2($l)){
//$sql4 = "update monks set flag = 1 where monk_id = $v";
$sql11 = "update monks set flag = 1 where monk_id = $monks[$k]";
//echo $sql4."<br>";
$sqlquery11 = mysqli_query($conn, $sql11) or die ("ไม่สามารถอัพเดตข้อมูลได้ กรุณาตรวจสอบข้อมูลอีกครั้ง".mysqli_error($conn));
}else{
echo "can't update flag = 1<br>";
}
//}
}
//}else{
// echo "can't update flag = 1<br>";
//}
}
}else{
echo "can't update flag = 1<br>";
}
}
}/**elseif ($icount2 = $icount1) {
echo "\$icount2 = \$icount1";
$sql8 = "delete from reserved where reservation_id=$reservation_id";
$result8 = mysqli_query($conn,$sql8) or die (mysqli_error($conn));
}**/
if ((($result1) and ($result2) and ($result3) and ($result4) or ($result5)) or (($result1) and ($result2) and ($result6) and ($result8) or ($result7))) {
//COMMIT TRANSACTION
normal_end:
mysqli_commit($conn);
mysqli_close($conn);
unset ($_SESSION['checked9']);
unset ($_SESSION['checked8']);
unset ($_session['checked7']);
//echo $_SESSION['start_date'];
unset ($_SESSION['start_date']);
unset ($_SESSION['end_date']);
//echo $_POST['start_date2']."<br>";
//echo $_POST['end_date2'];
echo "แก้ไขข้อมูลเรียบร้อยแล้ว";
echo "<hr>";
echo "<a href='workmain.php'>แสดงข้อมูลกิจนิมนต์</a>";
exit('</body></html>');
} else {
//ROLLBACK TRANSACTION
mysqli_rollback($conn);
unset ($_SESSION['checked9']);
unset ($_SESSION['checked8']);
unset ($_session['checked7']);
unset ($_SESSION['start_date']);
unset ($_SESSION['end_date']);
/**echo "\$result1=".$result1."<br>";
echo "\$result2=".$result2."<br>";
echo "\$result3=".$result3."<br>";
echo "\$result4=".$result4."<br>";
echo "\$result5=".$result5."<br>";
echo "\$result6=".$result6."<br>";
echo "\$result7=".$result7."<br>";**/
echo "เกิดข้อผิดพลาด ".mysqli_error($conn);
}
?>
</BODY>
</HTML>
Tag : PHP, MySQL, Ajax, jQuery, XAMPP, Windows
|
|
 |
 |
 |
 |
Date :
2019-07-11 15:29:50 |
By :
pairinon |
View :
687 |
Reply :
4 |
|
 |
 |
 |
 |
|
|
|
 |