รบกวนพี่ๆ ดู error โค้ดให้หน่อยครับ Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\KARA\page\check_room.php on line 26
คือผมจะทำปุ่มเช็ควันเวลาว่างครับ แต่พอกดเช็คแล้วมี error
Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\KARA\page\check_room.php on line 26
ฐานข้อมูล ทดสอบครับ
Code
-- phpMyAdmin SQL Dump
-- version 2.10.3
-- http://www.phpmyadmin.net
--
-- โฮสต์: localhost
-- เวลาในการสร้าง:
-- รุ่นของเซิร์ฟเวอร์: 5.0.51
-- รุ่นของ PHP: 5.2.6
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
--
-- ฐานข้อมูล: `KARA2560`
CREATE TABLE `meeting_list` (
`id` int(11) NOT NULL auto_increment,
`strdate` date NOT NULL,
`enddate` date NOT NULL,
`strtime` time NOT NULL,
`endtime` time NOT NULL,
`room` int(5) NOT NULL,
`room_type` int(5) NOT NULL,
`name` varchar(100) collate utf8_unicode_ci NOT NULL,
`qty` int(5) NOT NULL,
`user` int(5) NOT NULL,
`conduct` varchar(1) collate utf8_unicode_ci NOT NULL,
`conduct_1` varchar(1) collate utf8_unicode_ci NOT NULL,
`conduct_2` varchar(1) collate utf8_unicode_ci NOT NULL,
`conduct_3` varchar(1) collate utf8_unicode_ci NOT NULL,
`conduct_2_qty` int(2) NOT NULL,
`conduct_3_qty` int(2) NOT NULL,
`budget` varchar(1) collate utf8_unicode_ci NOT NULL,
`mstatus` varchar(1) collate utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=2 ;
--
-- dump ตาราง `meeting_list`
--
INSERT INTO `meeting_list` VALUES (1, '2017-07-08', '2017-07-08', '08:00:00', '12:00:00', 1, 1, 'ทดสอบการจองห้อง KARA1', 50, 1, 'Y', '', '', '', 0, 0, '1', 'S');
INSERT INTO `meeting_list` VALUES (2, '2017-07-08', '2017-07-08', '13:00:00', '16:00:00', 2, 1, 'ทดสอบการจองห้อง KARA2', 30, 1, 'N', 'Y', 'Y', 'Y', 2, 2, '1', 'S');
CREATE TABLE `meeting_room` (
`id` int(5) NOT NULL auto_increment,
`name` varchar(50) collate utf8_unicode_ci NOT NULL,
`status` varchar(1) collate utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=4 ;
--
-- dump ตาราง `meeting_room`
--
INSERT INTO `meeting_room` VALUES (1, 'KARA1', 'Y');
INSERT INTO `meeting_room` VALUES (2, 'KARA2', 'Y');
INSERT INTO `meeting_room` VALUES (3, 'KARA3', 'Y');
INSERT INTO `meeting_room` VALUES (4, 'KARA4', 'Y');
CREATE TABLE `meeting_room_type` (
`id` int(5) NOT NULL auto_increment,
`name` varchar(50) collate utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=3 ;
--
-- dump ตาราง `meeting_room_type`
--
INSERT INTO `meeting_room_type` VALUES (1, 'ห้องสัมมนา');
INSERT INTO `meeting_room_type` VALUES (2, 'ห้องอาหาร');
INSERT INTO `meeting_room_type` VALUES (3, 'อื่นๆ');[/code]
หน้า add_room.php
Code
<?php
include 'chk_session.php';
?>
<script language="JavaScript">
var HttPRequest = false;
function doCallAjax() {
HttPRequest = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
HttPRequest = new XMLHttpRequest();
if (HttPRequest.overrideMimeType) {
HttPRequest.overrideMimeType('text/html');
}
} else if (window.ActiveXObject) { // IE
try {
HttPRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
HttPRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!HttPRequest) {
alert('Cannot create XMLHTTP instance');
return false;
}
var url = 'check_room.php';
var pmeters = "myRoom=" + encodeURI( document.getElementById("txtRoom").value) +
"&myDate1=" + encodeURI( document.getElementById("datepicker-th-1").value ) +
"&myDate2=" + encodeURI( document.getElementById("datepicker-th-2").value ) +
"&myHour1=" + encodeURI( document.getElementById("h1").value ) +
"&myHour2=" + encodeURI( document.getElementById("h2").value ) +
"&myMin1=" + encodeURI( document.getElementById("m1").value ) +
"&myMin2=" + encodeURI( document.getElementById("m2").value ) ;
//var pmeters = 'myName='+document.getElementById("txtName").value+'&my2='; // 2 Parameters
HttPRequest.open('POST',url,true);
HttPRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
HttPRequest.setRequestHeader("Content-length", pmeters.length);
HttPRequest.setRequestHeader("Connection", "close");
HttPRequest.send(pmeters);
HttPRequest.onreadystatechange = function()
{
if(HttPRequest.readyState == 3) // Loading Request
{
document.getElementById("mySpan").innerHTML = "Now is Loading...";
}
if(HttPRequest.readyState == 4) // Return Request
{
document.getElementById("mySpan").innerHTML = HttPRequest.responseText;
}
}
/*
HttPRequest.onreadystatechange = call function .... // Call other function
*/
}
</script>
<style type="text/css">
table {
text-align: left;
}
</style>
<div class="row">
<div class="col-lg-12">
<h4 class="alert alert-info"><i class="fa fa-save fa-fw"></i> เพิ่มข้อมูลจองห้องอาหาร</h4>
</div>
<!-- /.col-lg-12 -->
</div>
<?php include 'f_thaidate.php';
include 'datepick.php'; ?>
<ul class="nav" id="side-menu" style="font-size:14px;">
<form method="post" action="add_meeting_list.php" id="add_meeting">
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-body">
<div class="row">
<div class="col-lg-6">
<div class="form-group">
<label> เวลาเริ่ม</label>
<input type="text" id="datepicker-th-1" name="date1" value="<?=$today;?>"> </td>
<label>เวลา</label>
<select name="hour1" id="hour1">
<option value="00"> 00 </option>
<option value="01"> 01 </option>
<option value="02"> 02 </option>
<option value="03"> 03 </option>
<option value="04"> 04 </option>
<option value="05"> 05 </option>
<option value="06"> 06 </option>
<option value="07"> 07 </option>
<option value="08"> 08 </option>
<option value="09"> 09 </option>
<? for($hour1=10;$hour1<24;$hour1++)
{
?>
<option value="<?=$hour1;?>"> <?=$hour1;?> </option>
<?
}
?>
:
</select> :
<select name="min1" id="min1">
<option value="00"> 00 </option>
<option value="01"> 01 </option>
<option value="02"> 02 </option>
<option value="03"> 03 </option>
<option value="04"> 04 </option>
<option value="05"> 05 </option>
<option value="06"> 06 </option>
<option value="07"> 07 </option>
<option value="08"> 08 </option>
<option value="09"> 09 </option>
<? for($min1=10;$min1<60;$min1++)
{
?>
<option value="<?=$min1;?>"> <?=$min1;?> </option>
<?
}
?>
</select> น.
</div></div>
<div class="form-group">สิ้นสุด
<input type="text" id="datepicker-th-2" name="date2" value="<?=$today;?>"> </td>
<label>เวลา</label>
<select name="hour2" id="hour2">
<option value="00"> 00 </option>
<option value="01"> 01 </option>
<option value="02"> 02 </option>
<option value="03"> 03 </option>
<option value="04"> 04 </option>
<option value="05"> 05 </option>
<option value="06"> 06 </option>
<option value="07"> 07 </option>
<option value="08"> 08 </option>
<option value="09"> 09 </option>
<? for($hour2=10;$hour2<24;$hour2++)
{
?>
<option value="<?=$hour2;?>"> <?=$hour2;?> </option>
<?
}
?>
</select> :
<select name="min2" id="min2">
<option value="00"> 00 </option>
<option value="01"> 01 </option>
<option value="02"> 02 </option>
<option value="03"> 03 </option>
<option value="04"> 04 </option>
<option value="05"> 05 </option>
<option value="06"> 06 </option>
<option value="07"> 07 </option>
<option value="08"> 08 </option>
<option value="09"> 09 </option>
<? for($min2=10;$min2<60;$min2++)
{
?>
<option value="<?=$min2;?>"> <?=$min2;?> </option>
<?
}
?>
</select> น.
</div></div>
<div class="row">
<div class="col-lg-4">
<div class="form-group">
<label> เลือกห้อง</label>
<?
$strSQL2 = "select * from meeting_room";
$objQuery2 = mysql_query($strSQL2) or die ("Error Query [".$strSQL2."]");
?>
<select name="txtRoom" id="txtRoom" >
<?
while($objResult2 = mysql_fetch_array($objQuery2))
{
?>
<option value='<?=$objResult2["id"];?>'><?=$objResult2["name"];?></option>
<?
}
?>
</select>
</div></div>
<div class="form-group">
<label> ใช้สำหรับ</label>
<?
$strSQL3 = "select * from meeting_room_type";
$objQuery3 = mysql_query($strSQL3) or die ("Error Query [".$strSQL3."]");
?>
<select name="txtRoomtype" >
<?
while($objResult3 = mysql_fetch_array($objQuery3))
{
?>
<option value='<?=$objResult3["id"];?>'><?=$objResult3["name"];?></option>
<? }
?>
</select>
</div>
</div>
<div class="row">
<div class="col-lg-6">
<div class="form-group">
<input type="button" class="btn btn-success" value="ตรวจสอบ" onClick="JavaScript:doCallAjax();">
<strong><span id="mySpan" style="color:#FF3333">คลิ๊กเพื่อตรวจสอบห้องก่อนนะครับ</span></strong>
</div>
</div></div>
<div class="row">
<div class="col-lg-12">
<div class="form-group">
<label>ชื่อลูกค้าที่จอง</label>
<input type="text" class="panjang" name="txtName">
</div></div>
<div class="form-group">
<label>เบอร์โทร</label>
<input type="text" class="pendek" name="txtQty">
</div>
<div class="form-group">
<label>จำนวน</label>
<input type="text" class="pendek" name="txtQty"> คน
</div>
<div class="row">
<div class="col-lg-4">
<div class="form-group">
<input type="submit" class="btn btn-success" value="ตกลง">
<button type="reset" class="btn btn-default">Reset</button>
</div>
</div>
</div>
</div>
</div></div></div></div></div></div></div>
</form>
</div></div></div>
หน้า check_room.php
Code
<?php require_once('../Connections/connect.php');
$time1 = $_POST["myHour1"].":".$_POST["myMin1"].":00";
$time2 = $_POST["myHour2"].":".$_POST["myMin2"].":00";
$strSQL = "SELECT * FROM meeting_list WHERE ((strdate between '".$_POST["myDate1"]."' and '".$_POST["myDate2"]."') or ";
$strSQL .= " (enddate between '".$_POST["myDate1"]."' and '".$_POST["myDate2"]."')) and ";
$strSQL .= " ((strtime between '".$time1."' and '".$time2."') or ";
$strSQL .= " (endtime between '".$time1."' and '".$time2."')) and room = '".$_POST["myRoom"]."' and mstatus in('Y','N') ";
$objQuery = mysql_query($strSQL);
$objResult = mysql_fetch_array($objQuery);
if($objResult)
{
echo "ห้องไม่ว่าง มีคนจองแล้ว !";
}
else
{
echo "ห้องว่าง สามารถจองได้ !";
}
?>
หน้า add_meeting_list.php
Code
[code]<?php require_once('../Connections/connect.php');
if(trim($_POST["txtName"]) == "")
{
echo "กรุณาระบุชื่อลูกค้า!";
exit();
}
if(trim($_POST["txtQty"]) == "")
{
echo "กรุณารุะบุเบอร์โทร!";
exit();
}
$time1 = $_POST["h1"].':'.$_POST["m1"].':00';
$time2 = $_POST["h2"].':'.$_POST["m2"].':00';
$strSQL = "SELECT * FROM meeting_list WHERE ((strdate between '".$_POST["date1"]."' and '".$_POST["date2"]."') or ";
$strSQL .= " (enddate between '".$_POST["date1"]."' and '".$_POST["date2"]."')) and ";
$strSQL .= " ((strtime between '".$time1."' and '".$time2."') or ";
$strSQL .= " (endtime between '".$time1."' and '".$time2."')) and room = '".$_POST["txtRoom"]."' and mstatus in('Y','N') ";
$objQuery = mysql_query($strSQL);
$objResult = mysql_fetch_array($objQuery);
if($objResult)
{
echo "วันและเวลาที่จองห้อง ไม่ว่าง!";
}
else
{
$strSQL1 = "INSERT INTO meeting_list ";
$strSQL1 .=" (id,strdate,enddate,strtime,endtime,room,room_type,name,qty,user,conduct,conduct_1,conduct_2,conduct_3,conduct_2_qty,conduct_3_qty,budget,mstatus) ";
$strSQL1 .=" VALUES (NULL,'".$_POST["date1"]."','".$_POST["date2"]."','".$time1."','".$time2."','".$_POST["txtRoom"]."','".$_POST["txtRoomtype"]."' ";
$strSQL1 .=" ,'".$_POST["txtName"]."','".$_POST["txtQty"]."','".$_SESSION['member_id']."','".$_POST["rdoConduct"]."' ";
$strSQL1 .=" ,'".$_POST["cbConduct1"]."','".$_POST["cbConduct2"]."','".$_POST["cbConduct3"]."','".$_POST["txtQtyconduct2"]."' ";
$strSQL1 .=" ,'".$_POST["txtQtyconduct3"]."','".$_POST["rdoBudget"]."','N')";
$objQuery1 = mysql_query($strSQL1);
echo "จองห้องอาหารเรียบร้อยแล้ว !";
}
mysql_close();
?>
</div>
</div>
</body>
</html>
Tag : PHP, MySQL
ประวัติการแก้ไข 2017-08-03 10:57:32
Date :
2017-08-03 10:55:45
By :
Lun2560
View :
1102
Reply :
2
ดูเรื่อง Connection หรือ SQL Statement ด้วยครับ
Date :
2017-08-03 11:48:31
By :
mr.win
Load balance : Server 00