Đặt vé xe buýt trực tuyến bằng PHP / MySQLi
1 <link href="src/facebox.css" media="screen" rel="stylesheet" type="text/css" />
2 <script src="lib/jquery.js" type="text/javascript"></script>
3 <script src="src/facebox.js" type="text/javascript"></script>
4 <script type="text/javascript">
5 jQuery(document).ready(function($) {
6 $('a[rel*=facebox]').facebox({
7 loadingImage : 'src/loading.gif',
8 closeImage : 'src/closelabel.png'
9 })
10 })
11 </script>
12 <style>
13 body{
14 font-family:"Lucida Grande", "Lucida Sans Unicode", Verdana, Arial, Helvetica, sans-serif;
15 font-size:12px;
16 }
17 p, h1, form, button{border:0; margin:0; padding:0;}
18 .spacer{clear:both; height:1px;}
19 /* ----------- My Form ----------- */
20 .myform{
21 margin:0 auto;
22 width:400px;
23 padding:14px;
24 }
25
26 /* ----------- stylized ----------- */
27 #stylized{
28 border:solid 2px #b7ddf2;
29 background:#ebf4fb;
30 }
31 #stylized h1 {
32 font-size:14px;
33 font-weight:bold;
34 margin-bottom:8px;
35 }
36 #stylized p{
37 font-size:11px;
38 color:#666666;
39 margin-bottom:20px;
40 border-bottom:solid 1px #b7ddf2;
41 padding-bottom:10px;
42 }
43 #stylized label{
44 display:block;
45 font-weight:bold;
46 text-align:right;
47 width:140px;
48 float:left;
49 }
50 #stylized .small{
51 color:#666666;
52 display:block;
53 font-size:11px;
54 font-weight:normal;
55 text-align:right;
56 width:140px;
57 }
58 #stylized input{
59 float:left;
60 font-size:12px;
61 padding:4px 2px;
62 border:solid 1px #aacfe4;
63 width:200px;
64 margin:2px 0 20px 10px;
65 }
66 #stylized button{
67 clear:both;
68 margin-left:150px;
69 width:125px;
70 height:31px;
71 background:#666666 url(img/button.png) no-repeat;
72 text-align:center;
73 line-height:31px;
74 color:#FFFFFF;
75 font-size:11px;
76 font-weight:bold;
77 }
78 </style>
79 <?php
80 include('db.php');
81 $busnum=$_POST['route'];
82 $date=$_POST['date'];
83 $qty=$_POST['qty'];
84 $result = mysqli_query($conn,"SELECT * FROM route WHERE id='$busnum'");
85 while($row = mysqli_fetch_array($result))
86 {
87 $numofseats=$row['numseats'];
88 $query = mysqli_query($conn,"SELECT sum(seat_reserve) FROM reserve where date = '$date'");
89 while($rows = mysqli_fetch_array($query))
90 {
91 $inogbuwin=$rows['sum(seat_reserve)'];
92 }
93 $avail=$numofseats-$inogbuwin;
94 $setnum=$inogbuwin+1;
95 }
96 ?>
97 <?php
98 if ($avail < $qty){
99 echo 'Qty reserve exced the available seat of the bus';
100 }
101 else if($avail > 0)
102 {
103 ?>
104 <script type="text/javascript">
105 function validateForm()
106 {
107 var x=document.forms["form"]["fname"].value;
108 if (x==null || x=="")
109 {
110 alert("First Name must be filled out");
111 return false;
112 }
113 var y=document.forms["form"]["lname"].value;
114 if (y==null || y=="")
115 {
116 alert("Last Name must be filled out");
117 return false;
118 }
119 var a=document.forms["form"]["address"].value;
120 if (a==null || a=="")
121 {
122 alert("Address must be filled out");
123 return false;
124 }
125 var b=document.forms["form"]["contact"].value;
126 if (b==null || b=="")
127 {
128 alert("Contact Number must be filled out");
129 return false;
130 }
131
132 }
133 </script>
134 <div id="stylized" class="myform">
135
136 <form id="form" name="form" action="save.php" method="post" onsubmit="return validateForm()">
137 <input type="hidden" value="<?php echo $busnum ?>" name="busnum" />
138 <input type="hidden" value="<?php echo $date ?>" name="date" />
139 <input type="hidden" value="<?php echo $qty ?>" name="qty" />
140 <label>Seat Number
141 <span class="small">Auto Generated <a rel="facebox" href="seatlocation.php?id=<?php echo $busnum; ?>">view seat</a></span>
142 </label>
143 <input type="text" name="setnum" value="
144 <?php
145 $N = $qty;
146 for($i=0; $i < $N; $i++)
147 {
148 echo $i+$setnum.', ';
149 }
150 ?>
151 " id="name" readonly/><br>
152 <label>First Name
153 <span class="small">Enter first name</span>
154 </label>
155 <input type="text" name="fname" id="name"/><br>
156 <label>Last Name
157 <span class="small">Enter last name</span>
158 </label>
159 <input type="text" name="lname" id="name"/><br>
160 <label>Address
161 <span class="small">Enter Address</span>
162 </label>
163 <input type="text" name="address" id="name"/><br>
164 <label>Contact
165 <span class="small">Enter Contact Number</span>
166 </label>
167 <input type="text" name="contact" id="name"/><br>
168 <button type="submit">Confirm</button>
169 </form>
170 </div>
171 <?php
172 }
173 else if($avail <= 0)
174 {
175 echo 'no available sets';
176 }
177 ?>