|
|
|
php+sql การบันทึกข้อมูลที่ดึงมาจาก sql แล้วจะส่งค่ากลับไปบันทึกอีกรอบ รบกวนช่วยดูทีครับ |
|
|
|
|
|
|
|
Code (PHP)
<?php
$hostname = 'localhost';
$username = 'root';
$password = 'root';
$databaseName = 'booking_room';
$connect = mysqli_connect($hostname, $username, $password, $databaseName);
$query1 = 'SELECT * FROM tb_room';
$query2 = 'SELECT * FROM tb_group';
$result1 = mysqli_query($connect, $query1);
$result2 = mysqli_query($connect, $query2);
$roomname = '';
while ($row2 = mysqli_fetch_array($result1)) {
$roomid = $roomid . "<option>$row2[0]</option>";
$roomname = $roomname . "<option>$row2[1]</option>";
}
$groupwork = '';
while ($row2 = mysqli_fetch_array($result2)) {
$grouid = $groupid . "<option>$row2[0]</option>";
$groupwork = $groupwork . "<option>$row2[1]</option>";
}
?>
<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
font-family: Arial, Helvetica, sans-serif;
background-color: black;
}
* {
box-sizing: border-box;
}
/* Add padding to containers */
.container {
padding: 16px;
background-color: white;
}
/* Full-width input fields */
input[type=text], input[type=password] {
width: 100%;
padding: 15px;
margin: 5px 0 22px 0;
display: inline-block;
border: none;
background: #f1f1f1;
}
input[type=text]:focus, input[type=password]:focus {
background-color: #ddd;
outline: none;
}
/* Overwrite default styles of hr */
hr {
border: 1px solid #f1f1f1;
margin-bottom: 25px;
}
/* Set a style for the submit button */
.registerbtn {
background-color: #4CAF50;
color: white;
padding: 16px 20px;
margin: 8px 0;
border: none;
cursor: pointer;
width: 100%;
opacity: 0.9;
}
.registerbtn:hover {
opacity: 1;
}
/* Add a blue text color to links */
a {
color: dodgerblue;
}
/* Set a grey background color and center the text of the "sign in" section */
.signin {
background-color: #f1f1f1;
text-align: center;
}
</style>
<meta charset="UTF-8">
<title>Booking Rooming - เพิ่มการจองข้อมูลห้อง</title>
</head>
<body>
<div class="container">
<form action="booking_save.php" name="frmAdd" method="post">
<table width="552" border="0" align="center">
<tbody>
<tr>
<th colspan="2" scope="col">รายละเอียดการจอง</th>
</tr>
<tr>
<th width="162" scope="row">ชื่อห้องที่จอง</th>
<td width="374">
<select>
<?php echo $roomname; ?>
</select>
</td>
</tr>
<tr>
<th scope="row">วันที่จอง</th>
<td><input name="date" type="date" id="date" autocomplete="on"></td>
</tr>
<tr>
<th scope="row">เริ่ม</th>
<td>
<select name="ddlstart" id="time_start">
<option value="07:00">07:00</option>
<option value="07:30">07:30</option>
<option value="08:00">08:00</option>
<option value="08:30">08:30</option>
<option value="09:00">09:00</option>
<option value="09:30">09:30</option>
<option value="10:00">10:00</option>
<option value="10:30">10:30</option>
<option value="11:00">11:00</option>
<option value="11:30">11:30</option>
<option value="12:00">12:00</option>
<option value="12:30">12:30</option>
<option value="13:00">13:00</option>
<option value="13:30">13:30</option>
<option value="14:00">14:00</option>
<option value="14:30">14:30</option>
<option value="15:00">15:00</option>
<option value="15:30">15:30</option>
<option value="16:00">16:00</option>
<option value="16:30">16:30</option>
<option value="17:00">17:00</option>
</select>
</td>
</tr>
<tr>
<th scope="row">สิ้นสุด</th>
<td>
<select name="ddlend" id="time_end">
<option value="08:00">08:00</option>
<option value="08:30">08:30</option>
<option value="09:00">09:00</option>
<option value="09:30">09:30</option>
<option value="10:00">10:00</option>
<option value="10:30">10:30</option>
<option value="11:00">11:00</option>
<option value="11:30">11:30</option>
<option value="12:00">12:00</option>
<option value="12:30">12:30</option>
<option value="13:00">13:00</option>
<option value="13:30">13:30</option>
<option value="14:00">14:00</option>
<option value="14:30">14:30</option>
<option value="15:00">15:00</option>
<option value="15:30">15:30</option>
<option value="16:00">16:00</option>
<option value="16:30">16:30</option>
<option value="17:00">17:00</option>
</select>
</td>
</tr>
<tr>
<th scope="row">หัวข้อการประชุม</th>
<td><input type="text" name="title" id="title" placeholder="หัวข้อการประชุม"></td>
</tr>
<tr>
<th scope="row">กลุ่มงาน</th>
<td>
<select >
<?php echo $groupwork; ?>
</select>
</td>
</tr>
<tr>
<th scope="row">ชื่อผู้จอง</th>
<td><input type="text" name="namelast" id="namelast" placeholder="กรุณาใส่ชื่อผู้จอง"></td>
</tr>
<tr>
<th scope="row">จำนวนคนเข้าร่วม</th>
<td><input type="text" name="people" id="people" placeholder="จำนวนบุคคลที่เข้าร่วม"></td>
</tr>
<tr>
<th colspan="2" scope="row">อุปกรณ์อำนวยความสะดวก</th>
</tr>
<tr>
<th scope="row">เครื่องเสียง</th>
<td color="red"><input type="checkbox" name="checksound" id="checksound" value="1"> *ติ๊กเพื่อใช้อุปกรณ์</td>
</tr>
<tr>
<th scope="row">คอมพิวเตอร์</th>
<td><input type="checkbox" name="checkcomputer" id="checkcomputer" value="1"> *ติ๊กเพื่อใช้อุปกรณ์</td>
</tr>
<tr>
<th scope="row">โปรเจคเตอร์</th>
<td><input type="checkbox" name="checkpro" id="checkpro" value="1"> *ติ๊กเพื่อใช้อุปกรณ์</td>
</tr>
<tr>
<th scope="row">เครื่องฉายสามมิติ</th>
<td><input type="checkbox" name="check3d" id="check3d" value="1"> *ติ๊กเพื่อใช้อุปกรณ์</td>
</tr>
<tr>
<th scope="row">โต๊ะ</th>
<td><input type="text" name="txttable" id="txttable" placeholder="โปรดระบุจำนวน"></td>
</tr>
<tr>
<th scope="row">เก้าอี้</th>
<td><input type="text" name="txtchiar" id="txtchiar" placeholder="โปรดระบุจำนวน"></td>
</tr>
<tr>
<th scope="row">จำนวนอาหารว่าง</th>
<td><input type="text" name="txtfood" id="txtfood" placeholder="ถ้ามีโปรดระบุ"></td>
</tr>
<tr>
<th scope="row">อื่นๆ</th>
<td><input type="text" name="txtorther" id="txtorther" placeholder="*ถ้ามีโปรดระบุ"> </td>
</tr>
<tr>
<th colspan="2" scope="row"><input type="submit" name="submit" value="submit" class="registerbtn"></th>
</tr>
</tbody>
</table>
</div>
</form>
</body>
</html>
<? mysqli_close($sqli); ?>
Code (PHP)
<?php
ini_set('display_errors', 1);
error_reporting(~0);
$roomid = $roomid;
$roomname = $_POST['roomname'];
$date = $_POST['date'];
$timestart = $_POST['ddlstart'];
$timeend = $_POST['ddlend'];
$title = $_POST['title'];
$groupid = $groupid;
$namelast = $_POST['namelast'];
$people = $_POST['people'];
$checksound = $_POST['checksound'];
$checkcomputer = $_POST['checkcomputer'];
$checkpro = $_POST['checkpro'];
$check3d = $_POST['check3d'];
$table = $_POST['txttable'];
$chiar = $_POST['txtchiar'];
$food = $_POST['txtfood'];
$orther = $_POST['txtorther'];
$serverName = "localhost";
$userName = "root";
$userPassword = "root";
$dbName = "booking_room";
$conn = mysqli_connect($serverName,$userName,$userPassword,$dbName);
$sql = "INSERT INTO tb_booking (room_id, roomname, date, time_start, time_end, title, groupwork, namelast, people, device_sound, device_com, device_pro, device_3d, device_table, device_chiar, device_brake, orther) VALUES ('$roomid','$nameroom','$date','$timestart','$timeend','$title','$groupid','$namelast','$people','$checksound','$checkcomputer','$checkpro','$check3d','$table','$chiar','$food','$orther')";
$query = mysqli_query($conn,$sql);
if($query) {
echo "Record add successfully";
}
mysqli_close($conn);
?>
Code (SQL)
-- phpMyAdmin SQL Dump
-- version 4.8.3
-- https://www.phpmyadmin.net/
--
-- Host: localhost:8889
-- Generation Time: May 22, 2019 at 09:47 AM
-- Server version: 5.7.23
-- PHP Version: 7.2.10
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
--
-- Database: `booking_room`
--
-- --------------------------------------------------------
--
-- Table structure for table `member`
--
CREATE TABLE `member` (
`UserID` int(3) UNSIGNED ZEROFILL NOT NULL,
`Username` varchar(20) NOT NULL,
`Password` varchar(20) NOT NULL,
`Name` varchar(100) NOT NULL,
`Status` enum('ADMIN','USER') NOT NULL DEFAULT 'USER'
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
--
-- Dumping data for table `member`
--
INSERT INTO `member` (`UserID`, `Username`, `Password`, `Name`, `Status`) VALUES
(001, 'admin', 'admin', 'admin admin', 'ADMIN');
-- --------------------------------------------------------
--
-- Table structure for table `tb_booking`
--
CREATE TABLE `tb_booking` (
`id` int(7) NOT NULL,
`room_id` int(3) NOT NULL,
`dateroom` date NOT NULL,
`start_time` time NOT NULL,
`end_time` time NOT NULL,
`title` varchar(50) NOT NULL,
`group_work` int(3) NOT NULL,
`namelast` varchar(30) NOT NULL,
`people_totel` int(4) NOT NULL,
`device_sound` int(1) NOT NULL DEFAULT '0',
`device_com` int(1) NOT NULL DEFAULT '0',
`device_pro` int(1) NOT NULL DEFAULT '0',
`device_3d` int(1) NOT NULL DEFAULT '0',
`device_table` int(1) NOT NULL DEFAULT '0',
`device_chiar` int(1) NOT NULL DEFAULT '0',
`device_brake` int(1) NOT NULL DEFAULT '0',
`other` varchar(200) NOT NULL,
`status` int(1) NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Dumping data for table `tb_booking`
--
INSERT INTO `tb_booking` (`id`, `room_id`, `dateroom`, `start_time`, `end_time`, `title`, `group_work`, `namelast`, `people_totel`, `device_sound`, `device_com`, `device_pro`, `device_3d`, `device_table`, `device_chiar`, `device_brake`, `other`, `status`) VALUES
(1, 1, '2019-04-28', '09:00:00', '16:00:00', 'test', 1, 'ผู้พัฒนาโปรแกรม', 1, 1, 1, 1, 1, 1, 1, 1, '1', 1);
-- --------------------------------------------------------
--
-- Table structure for table `tb_group`
--
CREATE TABLE `tb_group` (
`id` int(3) NOT NULL,
`group_work` varchar(30) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Dumping data for table `tb_group`
--
INSERT INTO `tb_group` (`id`, `group_work`) VALUES
(1, 'กลุ่มงานวิชาการ');
-- --------------------------------------------------------
--
-- Table structure for table `tb_room`
--
CREATE TABLE `tb_room` (
`room_id` int(3) NOT NULL,
`room_name` varchar(30) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Dumping data for table `tb_room`
--
INSERT INTO `tb_room` (`room_id`, `room_name`) VALUES
(1, 'ห้องประชุมจั่นเพชร'),
(2, 'น้องดาวเรือง'),
(3, 'ห้องชุมใหญ่');
--
-- Indexes for dumped tables
--
--
-- Indexes for table `member`
--
ALTER TABLE `member`
ADD PRIMARY KEY (`UserID`),
ADD UNIQUE KEY `Username` (`Username`);
--
-- Indexes for table `tb_booking`
--
ALTER TABLE `tb_booking`
ADD PRIMARY KEY (`id`);
--
-- Indexes for table `tb_group`
--
ALTER TABLE `tb_group`
ADD PRIMARY KEY (`id`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `member`
--
ALTER TABLE `member`
MODIFY `UserID` int(3) UNSIGNED ZEROFILL NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;
--
-- AUTO_INCREMENT for table `tb_booking`
--
ALTER TABLE `tb_booking`
MODIFY `id` int(7) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;
--
-- AUTO_INCREMENT for table `tb_group`
--
ALTER TABLE `tb_group`
MODIFY `id` int(3) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;
Tag : PHP, MySQL, MAMP
|
|
|
|
|
|
Date :
2019-05-22 16:48:05 |
By :
mzDeaThly |
View :
704 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ติดปัญหาตรงไหนครับ
|
|
|
|
|
Date :
2019-05-22 18:30:44 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|