|
|
|
JavaScript insert ข้อมูลขึ้น Database เเล้วไม่ย้อนกลับมาหน้าเดิม |
|
|
|
|
|
|
|
ทำหน้า insert ข้อมูลขึ้น Database โดยใช้ JavaScript เมื่อกดยืนยัน ข้อมูลเข้า Database เเล้วเเต่ไม่รันกลับมาหน้า product เดิมได้ต้องเเก้ไขตรงไหนหรอครับ
product.php
Code (PHP)
<?php
ob_start();
session_start();
if($_SESSION['userlan'] == '')
{
echo "<script language=\"JavaScript\">";
echo "alert('กรุณา Login');window.location='login.html';";
echo "</script>";
exit();
}
if($_SESSION['status'] != "A")
{
echo "This page for Admin only!";
exit();
}
?>
<HEAD>
<TITLE>
Restaurant Halal
</TITLE>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style type="text/css">
.container {
transition: box-shadow .3s;
border-radius:10px;
border: 1px solid #ccc;
padding: 20px;
}
</style>
</HEAD>
<CENTER><font size='18'>ยืนยันการจอง</font></CENTER>
<? echo $_SESSION['userlan'] ?><br>
<? echo $_SESSION['mobile'] ?><br>
<? echo $_SESSION['email'] ?><br>
<div class="container">
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner">
<?php
include("connection2.php");
$sql = "SELECT * FROM pic_product WHERE ProductID = '".$_GET['id']."'";
$result = mysqli_query($con,$sql);
$i = 1;
while($rs = mysqli_fetch_array($result)){
?>
<div class="item <?php if($i == 1){ print "active";} ?>">
<img src="<?php print $rs['pic_name']; ?>" alt="los" style="width:150%; height:560px;">
</div>
<?php
$i++;
}
?>
<!-- Left and right controls -->
<a class="left carousel-control" href="#myCarousel" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#myCarousel" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
<span class="sr-only">Next</span>
</a>
</div>
<?
include("connection2.php");
if (!isset($_GET['id'])){
header("location:product.php") ;
}
$sql = "select * from product where ProductID = '".$_GET['id']."'";
$result = mysqli_query($con,$sql) or die (mysqli_error());
$row = mysqli_num_rows($result);
if ($row > 0) {
print "<br>";
print "<table class='table table-striped table-bordered table-hover'";
print "<tr><th><div align ='center'>Product</div></th>";
print "<th><div align ='center'>Detail</div></th>";
print "<th><div align ='center'>Price</div></th>";
while ($rs = mysqli_fetch_array($result)){
print "<tr><td>" . $rs[1] . "</td>";
print "<td>" . $rs[2] . "</td>";
print "<td>" . $rs[3] . "</td>";
}
print "</table><br>";
}
?>
<center>
<form method="post" action="save_order.php" enctype="multipart/form-data">
<div class="form-group">
<label class="control-label col-sm-2">id</label>
<div class="col-sm-5">
<input type="text" class="form-control" name="txtidPro" value="<?=$_GET['id'] ?>" readonly>
</div><br><br>
</div>
<div class="form-group">
<label class="control-label col-sm-2">ชื่อ</label>
<div class="col-sm-5">
<input type="text" class="form-control" name="txtProName" value="<?=$_SESSION['userlan'] ?>" readonly>
</div><br><br>
</div>
<div class="form-group">
<label class="control-label col-sm-2">เบอร์</label>
<div class="col-sm-5">
<input type="text" class="form-control" name="txtTel" value="<?=$_SESSION['mobile'] ?>" readonly>
</div><br><br>
</div>
<div class="form-group">
<label class="control-label col-sm-2">อีเมล์</label>
<div class="col-sm-5">
<input type="text" class="form-control" name="txtEmail" value="<?=$_SESSION['email'] ?>" readonly><br>
<button type="submit" class="btn btn-success"><a href="JavaScript:if(confirm('ยืนยันการจองใช่หรือไม่') == true){window.location='save_order.php?id=<?=$_GET['id']?>';}">จอง</a></button>
<button type="cancel" class="btn btn-danger"><a href ='homepage.php'>ย้อนกลับ</a></button>
</div>
</div>
</div>
save_order.php
Code (PHP)
<?php
ob_start();
session_start();
?>
<?
include "connection.php";
$id = $_GET['id'];
$userlan = $_SESSION['userlan'];
$mobile = $_SESSION['mobile'];
$email = $_SESSION['email'];
$sql = "INSERT INTO orders ( OrderID,ProductID,Name,Tel,Email )
VALUES ( '','$id','$userlan','$mobile','$email' )";
print ($sql);
$result = mysqli_query($con,$sql) or die (mysqli_error());
if($result) {
echo "<script language='JavaScript'>";
echo "alert('ยืนยันการจองแล้ว');window.location='product.php?';";
echo "</script>";
}
?>
Tag : PHP, MySQL, HTML, JavaScript, Appserv, Windows
|
|
|
|
|
|
Date :
2019-03-13 12:00:28 |
By :
arknova2123 |
View :
1108 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
มีภาพประกอบไหม๊ครับ
|
|
|
|
|
Date :
2019-03-14 11:16:36 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|