Updating a text field based on Drop-down menu choice using ajax - php

I'm trying to update a text field (Price) whenever a drop-down menu (List of Products) item is selected. the text filed will show the selected item's price. I want to do this using ajax and i'm still new to this.
My code so far:
index.php
<?php
include 'Connection.php';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<link rel="stylesheet" href="Style.css">
<title>Shopping Cart</title>
</head>
<body>
<div id="mainPadding">
<h1 class="Shopping Title">The Shopping Items</h1>
<form class="form-horizontal">
<fieldset class="border p-2">
<legend class="w-auto">Contact Details:</legend>
<div class="form-group">
<label class="control-label col-sm-2" for="name">Name:</label>
<div class="col-sm-3">
<input type="name" required class="form-control" id="name" placeholder="Enter Your Name">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="email">Email:</label>
<div class="col-sm-3">
<input type="email" pattern="[a-z0-9._%+-]+#[a-z0-9.-]+\.[a-z]{2,}$" class="form-control" required id="email" placeholder="e.g. shop#shop.shop">
</div>
</div>
</fieldset>
<fieldset class="border p-2">
<legend class="w-auto">Available Items:</legend>
<div class="form-group">
<label class="col-lg-3 control-label">Item:</label>
<div class="col-sm-3">
<div class="ui-select">
<select id="ItemListDropDown" class="selectpicker" data-live-search="true">
<div id="itemList">
<?php
$sql = "SELECT Product_Name FROM products WHERE Availability = 1";
$result = mysqli_query($con, $sql);
if (mysqli_num_rows($result) > 0)
while ($row = mysqli_fetch_assoc($result))
echo "<option>" . $row["Product_Name"] . "</option>";
?>
</div>
</select>
</div>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="price">Price</label>
<div class="col-sm-3">
<input type="text" disabled class="form-control" id="priceTxt">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="price">Quantity (between 1 and 5):</label>
<div class="col-sm-3">
<input type="number" maxlength="1" min="1" max="5" class="form-control" id="priceTxt">
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label"></label>
<div class="col-md-8">
<input id="addToCart" type="button" class="btn btn-primary" value="Add to the Cart">
</div>
</div>
</fieldset>
<fieldset class="border p-2">
<legend class="w-auto">Invoice Details:</legend>
<div class="form-group">
<table class="table table-striped" id="ItemTable">
<thead>
<tr>
<th scope="col">Sr.</th>
<th scope="col">Item Name</th>
<th scope="col">Price</th>
<th scope="col">Count</th>
<th scope="col">Total</th>
<th scope="col">Delete</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row"></th>
<td id="ItemName"></td>
<td id="Price"></td>
<td id="Count"></td>
<td id="Total"></td>
<td id="DeleteButton"></td>
</tr>
</tbody>
</table>
<div class="form-group">
<label class="col-md-3 control-label"></label>
<div class="col-md-8">
<input id="PrintAndSend" type="submit" class="btn btn-primary" value="Print and Send to Email">
</div>
</div>
</div>
</fieldset>
</form>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<script src="Javascript.js"></script>
</body>
</html>
Javascrpt.js
$(document).ready(function() {
$("#ItemListDropDown").change(function() {
$("#itemList").load("load-product.php")
// $("#priceTxt").attr("value", price);
});
});
load-product.php
<?php
include 'Connection.php';
$sql = "SELECT Product_Name FROM products WHERE Availability = 1";
$result = mysqli_query($con, $sql);
if (mysqli_num_rows($result) > 0)
while ($row = mysqli_fetch_assoc($result))
echo "<option>" . $row["Product_Name"] . "</option>";
?>
I'm trying to do a few things using ajax, solving this will set me up for the rest.

Snake, you don't need Ajax to get your product price, instead just use a data-* attribute:
in your php (NOT the load-product.php file):
<?php
$sql = "SELECT Product_id, Product_Name, Product_price FROM products WHERE Availability = 1";
$result = mysqli_query($con, $sql);
if (mysqli_num_rows($result) > 0)
echo "<option value='default' data-price='default'>Choose a item </option>";
while ($row = mysqli_fetch_assoc($result))
echo "<option value='{$row["Product_id"}' data-price='{$row["Product_price"]}'>" . $row["Product_Name"] . "</option>";
?>
then in your javascript do this to get your item price:
// JavaScript using jQuery
$(function(){
$('#ItemListDropDown').change(function(){
var selected = $(this).find('option:selected');
var extra = selected.data('price');
$("#priceTxt").val(extra); // set your input price with jquery
$("#priceTxt").prop('disabled',false);//set the disabled to false maybe you want to edit the price
...
});
});
// Plain old JavaScript
var sel = document.getElementById('ItemListDropDown');
var selected = sel.options[sel.selectedIndex];
var extra = selected.getAttribute('data-price');
var priceInput = document.getElementById('priceTxt');
priceInput.disabled = false;
priceInput.value =extra;
Hope it helps =)

Related

I want to store data without showing it, every data when click store or input. So when click show I want to show. For code below did I do right?

I want to store data without showing it, every data when click store or input. So when click show I want to show data. but when put every new data and than click show just show new data without lost old data. For code below did I do right? Please help
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Using POST Method Session And Array</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col-sm-12 text-center mt-3">
<h1>Stock Keeping Unit</h1>
</div>
</div>
</div>
<div class="container mt-5">
<div class="row">
<div class="col-sm-4">
<div class="card">
<div class="card-header text-center">
<h3>Stock Card Input</h3>
</div>
<div class="card-body">
<form action="<?php echo ($_SERVER["PHP_SELF"]);?>" method="post">
<div class="mb-3">
<label for="name" class="form-label text-dark">Name<span class="text-danger">*</span></label>
<input type="text" class="form-control" name="name" id="name" placeholder="Enter Name">
</div>
<div class="mb-3">
<label for="product_name" class="form-label text-dark">Product Name <span class="text-danger">*</span></label>
<input type="text" class="form-control" name="product" id="product" placeholder="Enter Product Name">
</div>
<div class="mb-3">
<label for="quailty" class="form-label text-dark">Qty <span class="text-danger">*</span></label>
<input type="number" class="form-control" name="quailty" id="quailty" placeholder="Enter Qualty">
</div>
<div class="mb-3">
<label for="price" class="form-label text-dark">Price <span class="text-danger">*</span></label>
<input type="number" class="form-control" name="price" id="price" placeholder="Enter Price">
</div>
<div class="mb-3">
<input type="submit" name="store" value="store" class="btn btn-outline-primary">
<input type="submit" name="print" value="show" class="btn btn-outline-primary">
</div>
</form>
</div>
</div>
</div>
<div class="col-sm-8">
<div class="card">
<div class="card-header text-center">
<h3>Stock Table Show</h3>
</div>
<div class="card-body">
<table class="table table-bordered text-center">
<thead>
<tr>
<th scope="col">N</th>
<th scope="col">Name</th>
<th scope="col">Product Name</th>
<th scope="col">Qty</th>
<th scope="col">Price</th>
<th scope="col">Amount</th>
</tr>
</thead>
<tbody>
<?php
if(!empty($_POST['store'])){
// if(isset($_POST['store'])){
$_SESSION[' '][] = array(
'number' => '',
$name ='name' => $_POST["name"],
$product ='product' => $_POST["product"],
$quailty ='quailty' => $_POST["quailty"],
$price ='price' => $_POST["price"],
'amount' => '',
$name = $_POST["name"],
$product = $_POST["product"],
$quailty = $_POST["quailty"],
$price = $_POST["price"],
);
// }
//Loop row one by one when click save or store
for($a = 1; $a < count($_SESSION[' ']); $a++){
?>
<tr>
<?php
//Multiplecation of column Amount for one row inside loop
$_SESSION[' '][$a]['amount'] =
//Value of Quailty
(int)$_SESSION[' '][$a]['quailty']
*
//Value of Price
(int)$_SESSION[' '][$a]['price'];
//Loop All Data
foreach($_SESSION[' '][$a] as $key => $detail){
if($key == 'number'){
echo "<td>$a</td>";
}else if($key == 'name'){
echo "<td>". $detail ." </td>";
}else if($key == 'product'){
echo "<td>". $detail ."</td>";
}else if($key == 'quailty'){
echo "<td>". $detail ."</td>";
}else if($key == 'price'){
echo "<td>$". $detail ."</td>";
}else if($key == 'amount'){
echo "<td>$". $detail ."</td>";
}
}
?>
</tr>
<?php
}
//Loop Sum or Total of All Amount Column
$sum = 0;
for($b = 1; $b < count($_SESSION[' ']); $b++){
$sum += (int)$_SESSION[' '][$b]['amount'];
}
?>
</tbody>
</table>
<div class="container col-md-3 float-end bg-light">
<div class="input-group">
<h6 class="input-grout-text pt-1 mx-2">Total: <?php echo $sum .'$';
}
?></h6>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
I want to store data without showing it, every data when click store or input. So when click show I want to show data. but when put every new data and than click show just show new data without lost old data. For code below did I do right? Please help

How to get/pass the value to modal

How can I pass the value of order_id from order.php to ordermodal.php, So I can use it in my query.
This is the order.php
UI of order.php
<?php
session_start();
$order_id = $_SESSION['order_id'];
if (!isset($_SESSION['user_id']))
{
header("Location: index.php");
}
$_SESSION['navMenu'] = "order";
ini_set('display_errors', 'On');
require_once 'includes/database.php';
include_once 'system_menu.php';
include_once 'ordermodal.php';
$sql2 = "SELECT * FROM cart_tbl";
$sql = "SELECT * FROM order_tbl WHERE order_status = 'Accepted' or order_status = 'Dispatched' or order_status = 'Pending' ORDER BY order_datetime DESC";
/*** * SET UP COMBO BOX FOR SEARCH */
$comboBox = isset($_REQUEST['comboBoxVal']) ? trim($_REQUEST['comboBoxVal']) : '';
$search_by = isset($_REQUEST['search_by']) ? addslashes($_REQUEST['search_by']) : 0;
$users = null;
if ($comboBox != '') { switch ($search_by) {
case 1://Order ID
$sql .= " WHERE order_id LIKE '%{$comboBox}%' ";
break;
}
}
$carts = mysqli_query(connection(), $sql2);
$orders = mysqli_query(connection(), $sql);
$search_filters = array(1 => 'Order ID');
/*** * END SET UP COMBO BOX */ ?>
<html>
<head>
<title>ORDERS</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<link href="css/bootstrap.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"> </script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
<style type="text/css">
body {
background:url(images/jerica.jpg)fixed no-repeat center;
background-size:cover;
}
.asd {
color: white;
}
</style>
</head>
<body>
<?php
if (isset($_SESSION['message'])) {
$message = $_SESSION['message']; unset($_SESSION['message']);
}
else {
$message = "";
}
?> <div class="container" >
<h1 class="asd">Orders</h1>
</div> <div class="container" >
<div class="panel panel-default" >
<div class="panel-heading"> <form method="post"> <div class="input-group">
<div class="input-group-addon"> <select name="search_by">
<?php
foreach ($search_filters as $key => $value): ?>
<option value="<?= $key ?>" <?= $key == $search_by ? 'selected' : '' ?> > <?= $value ?> </option>
<?php
endforeach;
?>
</select>
</div>
<input type="search" name="comboBoxVal" value="<?= $comboBox ?>" class="form-control" placeholder="Search">
</div>
</form>
</div>
<div class="panel-body">
<?php
if ($message != ''): ?>
<div class="alert alert-success alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true"> ×</span></button>
<?= $message ?> </div>
<?php endif; ?>
<table class="table table-hover table-bordered">
<thead>
<tr>
<th>Order ID</th>
<th>User ID</th>
<th>Order Date</th>
<th>Order Time</th>
<th>Delivery Charge</th>
<th>Total Amount</th>
<th>Address</th>
<th>Coordinates</th>
<th>Driver Number</th>
<th>Order Status</th>
<th>Action</th>
</tr>
</thead>
<?php
/*** * DISPLAY TABLE */
?>
<tbody>
<?php if ($orders): ?>
<?php
while ($order = mysqli_fetch_array($orders, MYSQLI_BOTH)):
?>
<?php
$order_datetime = $order['order_datetime'];
$date = date('Y-m-d', strtotime($order_datetime));
$time = date('H:i:s', strtotime($order_datetime));
?>
<tr>
<td><?= $order['order_id'] ?></td>
<td><?= $order['user_id'] ?></td>
<td><?= $date ?></td>
<td><?= $time ?></td>
<td><?= $order['order_deliveryCharge'] ?></td>
<td><?= $order['order_totalAmount'] ?></td>
<td><?= $order['address'] ?></td>
<td><?= $order['coordinates'] ?></td>
<td><?= $order['driver_number'] ?></td>
<td><?= $order['order_status'] ?></td>
<td><button type="button" class="btn btn-success" data-toggle="modal" data-target="#myModal" onclick="viewOrder( '<?= $order['order_id'] ?>', '<?= $order['order_id'] ?>', '<?= $date ?>', '<?= $time ?>', '<?= $order['order_deliveryCharge'] ?>', '<?= $order['order_totalAmount'] ?>', '<?= $order['address'] ?>', '<?= $order['coordinates'] ?>', '<?= $order['driver_number'] ?>', '<?= $order['order_status'] ?>')"> View Order </button>
</td>
</tr>
<?php endwhile; ?>
<?php endif; ?>
</tbody>
</table>
</div>
<div class="panel-footer">
</div>
</div>
</div>
<script>
function viewOrder(order_id, user_id, order_date, order_time, order_deliveryCharge, order_totalAmount, address, coordinates, driver_number, order_status) {
document.getElementById("titleModal").innerHTML = "viewOrder";
document.getElementsByName("order_id")[0].setAttribute("value", order_id);
document.getElementsByName("user_id")[0].setAttribute("value", user_id);
document.getElementsByName("order_date")[0].setAttribute("value", order_date);
document.getElementsByName("order_time")[0].setAttribute("value", order_time);
document.getElementsByName("order_deliveryCharge")[0].setAttribute("value", order_deliveryCharge);
document.getElementsByName("order_totalAmount")[0].setAttribute("value", order_totalAmount);
document.getElementsByName("address")[0].setAttribute("value", address);
document.getElementsByName("coordinates")[0].setAttribute("value", coordinates);
document.getElementsByName("driver_number")[0].setAttribute("value", driver_number);
document.getElementsByName("order_status")[0].setAttribute("value", order_status);
document.getElementsByName("viewOrder")[0].setAttribute("name", "viewOrder");
/*x = document.getElementsByName("order_status").value;
if(x == "Accepted"){
document.getElementsByName("submitAccept").disabled = true;
}*/
}
</script?
</body>
</html>
And this is the ordermodal.php
UI of ordermodal.php
<?php
/** *ordermodal.php **/
$id = "";
$order_date = "";
$order_time = "";
$order_id = "";
$order_deliverCharge = "";
$order_status = "";
$order_totalAmount= "";
$coordinates = "";
$driver_number = "";
$address = "";
$food_name="";
$special_request="";
$quantity="";
$amount="";
$orders="";
?>
<!-- MODALS --> <!-- DETAILS -->
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<form action="" method="post" class="form-horizontal">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><center>×</button>
<h4 class="modal-title" id="titleModal"></h4>
</div>
<div class="modal-body">
<div class="form-group">
<label for="order_id" class="col-sm-2 control-label">Order ID</label>
<div class="col-lg-3">
<input type="text" input style="width:500px" class="form-control" name="order_id" id="order_id" placeholder="" value="" required="required" readonly>
</div>
</div>
<div class="form-group">
<label for="id" class="col-sm-2 control-label">ID</label>
<div class="col-lg-3">
<input type="text" input style="width:500px" class="form-control" name="user_id" id="user_id" placeholder="" value="" required="required" readonly>
</div>
</div>
<div class="form-group">
<label for="order_date" class="col-sm-2 control-label">Order Date</label>
<div class="col-lg-3">
<input type="text" input style="width:500px" class="form-control" name="order_date" id="order_date" placeholder="" value="" required="required" readonly>
</div>
</div>
<div class="form-group">
<label for="order_time" class="col-sm-2 control-label">Order Time</label>
<div class="col-lg-3">
<input type="text" input style="width:500px" class="form-control" name="order_time" id="order_time" placeholder="" value="" required="required" readonly>
</div>
</div>
<div class="form-group">
<label for="order_deliverCharge" class="col-sm-2 control-label">Delivery Charge</label>
<div class="col-lg-3">
<input type="text" input style="width:500px" class="form-control" name="order_deliveryCharge" id="order_deliveryCharge" placeholder="" value="" required="required" readonly>
</div>
</div>
<div class="form-group">
<label for="order_totalAmount" class="col-sm-2 control-label">Total Amount</label>
<div class="col-lg-3">
<input type="text" input style="width:500px" class="form-control" name="order_totalAmount" id="order_totalAmount" placeholder="" value="" required="required" readonly>
</div>
</div>
<div class="form-group">
<label for="address" class="col-sm-2 control-label">Address</label>
<div class="col-lg-3">
<input type="text" input style="width:500px" class="form-control" name="address" id="address" placeholder="" value="" required="required" readonly>
</div>
</div>
<div class="form-group">
<label for="coordinates" class="col-sm-2 control-label">Coordinates</label>
<div class="col-lg-3">
<input type="text" input style="width:500px" class="form-control" name="coordinates" id="coordinates" placeholder="" value="" required="required" maxlength="11" readonly>
</div>
</div>
<div class="form-group">
<label for="driver_number" class="col-sm-2 control-label">Driver Number</label>
<div class="col-lg-3">
<input type="text" input style="width:500px" class="form-control" name="driver_number" id="driver_number" placeholder="" value="" required="required" readonly>
</div>
</div>
<div class="form-group">
<label for="order_status" class="col-sm-2 control-label">Order Status</label>
<div class="col-lg-3">
<input type="text" input style="width:500px" class="form-control" name="order_status" id="order_status" placeholder="" value="" required="required" readonly>
</div>
</div>
<?php
// This is where I want to get the value of oder_id from order.php page
$sql = "SELECT food_name, special_request, quantity, amount
FROM cart_tbl
WHERE order_id=$order_id";
$result = mysqli_query(connection(), $sql);
?>
<table class="table table-hover table-bordered">
<thead>
<tr>
<th>Food</th>
<th>Special Request</th>
<th>Quantity</th>
<th>Amount</th>
</tr>
</thead>
<?php
if(mysqli_num_rows($result)>0)
{
while($row = mysqli_fetch_array($result))
{
?>
<tr>
<td><?php echo $row["food_name"];?></td>
<td><?php echo $row["special_request"];?></td>
<td><?php echo $row["quantity"];?></td>
<td><?php echo $row["amount"];?></td>
</tr>
<?php
}
}
?>
</table>
<tbody>
</div>
<div class="modal-footer">
<button type="submit" name="showOrder" id="showOrder" class="btn btn-secondary" onclick="" > Show Order </button>
<button type="submit" name="submitAccept" id="submitAccept" class="btn btn-primary" onclick="if(!confirm('Are you sure you want to accept order?')){return false;}" > Accept </button>
<button type="submit" name="submitSent" class="btn btn-primary"onclick="if(!confirm('Are you sure you want to send order?')){return false;}" >Sent</button>
<button type="submit" name="submitCancel" class="btn btn-danger" onclick="if(!confirm('Are you sure you want to cancel order?')){return false;}">Cancel</button>
<?php
if(isset($_POST['showOrder'])){
$order_id = trim(addslashes($_POST['order_id']));
}
if(isset($_POST['submitAccept'])){
$order_id = trim(addslashes($_POST['order_id']));
$query = "UPDATE order_tbl SET `order_status`='Accepted' WHERE `order_id` = $order_id";
if (mysqli_query(connection(), $query)) {
mysqli_query(connection(), "COMMIT");
$_SESSION['message'] = "Order Accepted"; }
else {
$_SESSION['message'] = mysqli_error(connection());
mysqli_query(connection(), "ROLLBACK");
}
}
if(isset($_POST['submitSent'])){
$order_id = trim(addslashes($_POST['order_id']));
$query = "UPDATE order_tbl SET `order_status`='Dispatched' WHERE `order_id` = $order_id";
if (mysqli_query(connection(), $query)) {
mysqli_query(connection(), "COMMIT");
$_SESSION['message'] = "Order Dispatched"; }
else {
$_SESSION['message'] = mysqli_error(connection());
mysqli_query(connection(), "ROLLBACK");
}
}
if(isset($_POST['submitCancel'])){
$order_id = trim(addslashes($_POST['order_id']));
$query = "UPDATE order_tbl SET `order_status`='Cancelled' WHERE `order_id` = $order_id";
if (mysqli_query(connection(), $query)) {
mysqli_query(connection(), "COMMIT");
$_SESSION['message'] = "Order Cancelled"; }
else {
$_SESSION['message'] = mysqli_error(connection());
mysqli_query(connection(), "ROLLBACK");
}
}
?>
</div>
</form>
</div>
</div>
</div>
So the function of this as the moment is when clicked the view order the value of the order_id from order.php didnt get, you need first to click the button inside the ordermodal.php(accept,send,cancel) in order to get the value of order_id.
"When I click the view order, I'll get right away the value of order_id so that I can use it in my sql query. This is what supposed to be the real output."
Hope you guys can help me, I stacked at this error for a couple of days already. TIA!
Couldn't you still use the session var you did in the first chunk...unless you are reseting that value - but didn't see that...
Alternatively... the url you are calling to get the url for the modal you could put a query param of OID=# and than do the typical...
$orderID = $_GET['old'] ? $_GET['old'] : $_POST['old']; // not sure if your posting or just doing a get....
Also no sure if your pulling this in through an iframe or what not but either way query param or session var should work.
Hope this helps.

Adding data to database using modal form in bootstrap

I've been really struggling with this today. Can't seem to get it to work, all it does is navigates to 'add-entry.php?go' in the navbar, but goes grey then reloads the index.php with modal still intact with my entries in it.
Here's my html, including the form and javascript filter input.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>ProSys Component Lookup</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="favicon.ico">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script> <!--Custom CSS -->
<link rel="stylesheet" href="css/main.css">
</head>
<body>
<!-- Wrapper -->
<div class="container-fluid">
<div class="col-xs-12">
<div class="col-xs-12">
<!-- Header -->
<div class="page-header">
<h1>ProSys Component Lookup</h1><br>
</div>
<!-- Main table content -->
<div class="container-fluid">
<button type="button" class="btn btn-primary btn-block" data-toggle="modal" data-target="#myModal">Add New Item</button><br>
<div class="modal fade" role="dialog" id="myModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Add New Item</h4>
</div>
<div class="modal-body">
<form method="post" action="add-entry.php?go" role="form">
<div class="form-group">
<label for="location">Location:</label>
<input type="text" class="form-control" name="location">
</div>
<div class="form-group">
<label for="category">Category:</label>
<select class="form-control" name="category">
<option>Processor</option>
<option>Diode</option>
<option>Fuse</option>
<option>Regulator</option>
<option>Capacitor</option>
<option>Inductor</option>
<option>LED</option>
<option>Gate</option>
<option>Modem</option>
<option>Transceiver</option>
<option>Thermistor</option>
<option>Load Switch</option>
<option>Op Amp</option>
<option>Optocoupler</option>
<option>Line Driver</option>
<option>ESD Protection</option>
<option>ADC</option>
<option>RTC</option>
</select>
</div>
<div class="form-group">
<label for="manufacturer">Manufacturer:</label>
<input type="text" class="form-control" name="manufacturer">
</div>
<div class="form-group">
<label for="description">Description:</label>
<textarea type="text" class="form-control" name="description" rows="5"></textarea>
</div>
<div class="form-group">
<label for="packagesize">PackageSize:</label>
<input type="text" class="form-control" name="packagesize">
</div>
<div class="form-group">
<label for="category">Supplier:</label>
<select class="form-control" name="supplier">
<option>Farnell</option>
<option>RS</option>
<option>Rapid</option>
</select>
</div>
<div class="form-group">
<label for="suppliernumber">Supplier Number:</label>
<input type="text" class="form-control" name="suppliernumber">
</div>
<div class="form-group">
<label for="stock">Stock:</label>
<input type="text" class="form-control" name="stock">
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-default">Add</button>
</div>
</form>
</div>
</div>
</div>
</div>
<!-- Search box -->
<div class="col-md-3">
<form class="styled">
<input type="text" class="form-control" onkeyup="myFunctionOne()" id="myInput" placeholder="Search..">
</form><br>
</div>
<div class="panel">
<div class="panel-body">
<div class="row">
<div class="col-xs-12">
<table class="table table-hover" id="table_demo">
<thead>
<tr>
<th>Location</th>
<th>Manufacturer</th>
<th>Description</th>
<th>PackageSize</th>
<th>Supplier</th>
<th>SupplierNumber</th>
<th>Stock</th>
</tr>
</thead>
<tbody id="myTable">
<tr>
<!-- Database connect and display as table -->
<?php
include("dbconnect.php");
$result = mysql_query("SELECT DrawLocation, Manufacturer, Description, PackageSize, Supplier, SupplierNumber, Stock FROM complibrary");
while($complibrary = mysql_fetch_array($result))
{
echo"<td>".$complibrary['DrawLocation']."</td>";
echo"<td>".$complibrary['Manufacturer']."</td>";
echo"<td>".$complibrary['Description']."</td>";
echo"<td>".$complibrary['PackageSize']."</td>";
echo"<td>".$complibrary['Supplier']."</a></td>";
//IF statement adds in links for web search via SupplierNumber
if ($complibrary['Supplier'] == 'Farnell') {
echo"<td><a target='_blank' href='http://uk.farnell.com/search?st=".$complibrary['SupplierNumber']."'>".$complibrary['SupplierNumber']."</a></td>";
} elseif ($complibrary['Supplier'] == 'RS') {
echo"<td><a target='_blank' href='http://uk.rs-online.com/web/c/?sra=oss&r=t&searchTerm=".$complibrary['SupplierNumber']."'>".$complibrary['SupplierNumber']."</a></td>";
} elseif ($complibrary['Supplier'] == 'Rapid') {
echo"<td><a target='_blank' href='https://www.rapidonline.com/Catalogue/Search?query=".$complibrary['SupplierNumber']."'>".$complibrary['SupplierNumber']."</a></td>";
} else {
echo"<td>".$complibrary['SupplierNumber']."</td>";
}
//IF statement end
echo"<td>".$complibrary['Stock']."</td>";
echo "</tr>";
}
mysql_close($conn);
?>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
<!-- Latest jQuery -->
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<!-- Filtering script -->
<script>
function myFunctionOne() {
var input, filter, table, tr, td, i;
input = document.getElementById("myInput");
filter = input.value.toUpperCase();
table = document.getElementById("myTable");
tr = table.getElementsByTagName("tr");
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[2];
if (td) {
if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}
</script>
</html>
And here's my add-entry.php
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<?php
if (isset($_POST['location'])){
$hostname = "localhost";
$username = "root";
$password = "";
$dbname = "componentlookup";
$conn = mysql_connect($hostname, $username, $password);
if (!$conn) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db($dbname, $conn);
$location = $_POST['location'];
$category = $_POST['category'];
$manufacturer = $_POST['manufacturer'];
$description = $_POST['description'];
$packagesize = $_POST['packagesize'];
$supplier = $_POST['supplier'];
$suppliernumber = $_POST['suppliernumber'];
$stock = $_POST['stock'];
$query = mysql_query("INSERT INTO 'complibrary' (ID, DrawLocation, Category, Manufacturer, Description, PackageSize, Supplier, SupplierNumber, Stock) VALUES ('NULL', '$location', '$category', '$manufacturer', '$description', '$packagesize', '$supplier', '$suppliernumber', '$stock')");
echo "Item added sucessfully. Click <a href='index.php'>HERE</a> to go back.";
mysql_close($conn);
}
?>
</body>
</html>
Any ideas?
I think you should put data-dismiss="modal" on the add button to close the window.
Also, I think you should not use mysql connection. Better, use mysqli or PDO.

MySQL insert multiple records from select please view code

Hi I want to bring this information to insert multiple records from select
This all FORM
<?php
session_start();
//PUT THIS HEADER ON TOP OF EACH UNIQUE PAGE
if(!isset($_SESSION['id_user'])){
header("location:../index.php");
header("Content-type: text/html; charset=utf-8");
}
include "config.php";
$strSQL = "SELECT * FROM vn_order order by id_vn_order desc ";
$objQuery = mysqli_query($mysqli,$strSQL);
$sqlus = "SELECT * FROM vn_user WHERE id_user = '".$_SESSION['id_user']."' ";
$objQu = mysqli_query($mysqli,$sqlus);
$objResult = mysqli_fetch_array($objQu);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Limitless - Responsive Web Application Kit by Eugene Kopyov</title>
<!-- Global stylesheets -->
<link href='https://fonts.googleapis.com/css?family=Kanit&subset=thai,latin' rel='stylesheet' type='text/css'>
<link href="assets/css/icons/icomoon/styles.css" rel="stylesheet" type="text/css">
<link href="assets/css/bootstrap.css" rel="stylesheet" type="text/css">
<link href="assets/css/core.css" rel="stylesheet" type="text/css">
<link href="assets/css/components.css" rel="stylesheet" type="text/css">
<link href="assets/css/colors.css" rel="stylesheet" type="text/css">
<link href="assets/css/sweet-alert.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="assets/js/alert/sweet-alert.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script src="respond.js"></script>
<style type="text/css">
body {
font-family: 'Kanit', sans-serif;
}
</style>
</head>
<body onLoad="setPostBack();">
<?php require_once("inc/header_menu.php") ?>
<!-- /user menu -->
<?php require_once("inc/menu.php") ?>
<!-- Main content -->
<div class="content-wrapper">
<!-- Content area -->
<div class="content">
<!-- Basic datatable -->
<div class="panel panel-flat">
<div class="panel-heading">
<h5 class="panel-title">จองรถตู้</h5>
<div class="heading-elements">
<ul class="icons-list">
<li><a data-action="collapse"></a></li>
<li><a data-action="reload"></a></li>
<li><a data-action="close"></a></li>
</ul>
</div>
</div>
<div class="panel-body">
</div>
<form role="form" action="dorent.php" method="post" onSubmit="return doSubmit();">
<input type="hidden" value="1" name="id_user"/>
<input type="hidden" value="1" name="id_invoice"/>
<input type="hidden" value="1" name="travellist_id"/>
<input type="hidden" value="Approve" name="Status"/>
<div class="panel-body">
<div class="row">
<div class="col-md-6">
<fieldset>
<legend class="text-semibold"><i class="icon-reading position-left"></i> Personal details</legend>
<div class="form-group">
<label>ชื่อ</label>
<input type="text" class="form-control" placeholder="ชื่อ" name="rn_first_name" id="rn_first_name" value="<?php echo $objResult["firstname"];?>" readonly>
</div>
<div class="form-group">
<label>นามสกุล:</label>
<input type="text" class="form-control" placeholder="นามสกุล" name="rn_last_name" id="rn_last_name" value="<?php echo $objResult["lastname"];?>"readonly>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label>E-mail</label>
<input type="text" class="form-control" placeholder="Email" name="" id="" value="<?php echo $objResult["email"];?>"readonly>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label>เบอร์โทรศัพท์</label>
<input type="text" class="form-control format-phone-number" name="rn_tel" id="rn_tel" placeholder="เบอร์ติดต่อ" value="<?php echo $objResult["Tel"];?>"maxlength="10" readonly>
</div>
</div>
</div>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
var obj_a = $("#rn_amount");
var obj_b = $("#data_b");
// a เปลี่ยนเมื่อ keyup แล้ว b เปลี่ยน ตามเงื่อนไขค่า a
obj_a.on("keyup",function(){
var value_obj_a = parseInt($(this).val()); // เก็บค่า a ไว้ในตัวแปร (parseInt คือเปลงเป็นเลข)
if(value_obj_a>9){ // กำหนดเงื่อนไขให้กับค่า a
obj_b.val(2); // เปลี่ยนค่า b เป้น 3
}else{
obj_b.val(1); // เปลี่ยนค่า b เป็น 1
}
});
});
</script>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label>จำนวนวนคนที่ไป</label>
<input type="text" name="rn_amount" id="rn_amount" value="" class="form-control"><br>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label class="display-block text-semibold">ประเภทรถตู้</label>
<select name="data_b" id="data_b" class="form-control">
<option value=""> Select </option>
<option value="1">9</option>
<option value="2">13</option>
</select>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<legend class="text-semibold"><i class="icon-truck position-left"></i> Shipping details</legend>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label>วันที่จอง : (วันที่ไป)</label>
<input class="form-control" type="date" name="rn_gostart" id="rn_gostart">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>วันที่กลับ : (วันกลับ)</label>
<input class="form-control" type="date" name="rn_endstart" id="rn_endstart">
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label>เวลาเดินทางไป</label>
<input class="form-control" type="time" name="time_gostart" id="time_gostart">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>เวลาเดินทางกลับ</label>
<input class="form-control" type="time" name="time_endstart" id="time_endstart">
</div>
</div>
</div>
<!-- เลือกสถานที่ท่องเที่ยว -->
<input type="hidden" id="txtNum" value="1" size="2" />
<table border="0" width="100%">
<thead>
<tr>
<th>
<div class="row">
<div class="col-md-10">
<div class="form-group">
<label class="display-block text-semibold"> จังหวัดที่ท่องเที่ยว</label>
<select name="province_id[]" id="selProvince" class="select-search">
<option value="">กรุณาเลือกจังหวัด</option>
<?php
include("connect.inc.php");
$SelectPr="SELECT * FROM province";
$QueryPro=mysql_query($SelectPr);
while($Pro=mysql_fetch_array($QueryPro)){
?>
<option value="<?=$Pro['province_id']?>"><?=$Pro['province_name']?></option>
<?php } ?>
</select>
</div>
</div>
</div>
</th>
<th>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label class="display-block text-semibold"> สถานที่ท่องเที่ยว</label>
<select id="selTravel" name="travel_id[]" class="select-search"><option value="">กรุณาเลือกจังหวัด</option></select>
</div>
</div>
</div>
</div>
</th>
<th>
</th>
</tr>
<tr><td><center>รายการที่เพิ่ม</center></td></tr>
</thead>
<tbody>
</tbody>
</table>
<div class="row">
<div class="form-group">
<div class="col-md-6">
<button type="button" id="btnP">เพิ่มรายการ</button>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label class="display-block text-semibold"> สถานที่ไปรับ</label>
<input class="form-control" type="text" name="rn_place" autocomplete="off">
</div>
</div>
</div>
<div class="form-group">
<label>สถานที่เพิ่มเติมระหว่างทาง</label>
<textarea rows="5" cols="5" class="form-control" name="vn_dtial" placeholder="Enter your message here"></textarea>
</div>
</fieldset>
</div>
</div>
<div class="text-right">
<button type="submit" class="btn btn-primary">Submit form <i class="icon-arrow-right14 position-right"></i></button>
</div>
</div>
</div>
</form>
<!-- Footer -->
<div class="footer text-muted f-xs text-center">
© 2016. ระบบจองรถตู้ออนไลน์ by ออนทัว
</div>
<!-- /footer -->
</div>
</div>
</div>
</div>
<!-- Core JS files -->
<script type="text/javascript" src="assets/js/plugins/loaders/pace.min.js"></script>
<script type="text/javascript" src="assets/js/core/libraries/jquery.min.js"></script>
<script type="text/javascript" src="assets/js/core/libraries/bootstrap.min.js"></script>
<script type="text/javascript" src="assets/js/plugins/loaders/blockui.min.js"></script>
<!-- /core JS files -->
<script type="text/javascript" src="assets/js/core/libraries/jquery_ui/interactions.min.js"></script>
<script type="text/javascript" src="assets/js/plugins/forms/selects/select2.min.js"></script>
<script type="text/javascript" src="assets/js/pages/form_select2.js"></script>
<script type="text/javascript" src="assets/js/plugins/forms/styling/uniform.min.js"></script>
<script type="text/javascript" src="assets/js/core/app.js"></script>
<script type="text/javascript" src="assets/js/pages/form_layouts.js"></script>
<script type="text/javascript" src="assets/js/plugins/forms/styling/uniform.min.js"></script>
<script type="text/javascript" src="assets/js/plugins/forms/styling/switchery.min.js"></script>
<script type="text/javascript" src="assets/js/plugins/forms/styling/switch.min.js"></script>
<script type="text/javascript" src="assets/js/pages/form_checkboxes_radios.js"></script>
</table>
</body>
</html>
This is the only required
<table border="0" width="100%">
<thead>
<tr>
<th>
<div class="row">
<div class="col-md-10">
<div class="form-group">
<label class="display-block text-semibold"> จังหวัดที่ท่องเที่ยว</label>
<select name="province_id[]" id="selProvince" class="select-search">
<option value="">กรุณาเลือกจังหวัด</option>
<?php
include("connect.inc.php");
$SelectPr="SELECT * FROM province";
$QueryPro=mysql_query($SelectPr);
while($Pro=mysql_fetch_array($QueryPro)){
?>
<option value="<?=$Pro['province_id']?>"><?=$Pro['province_name']?></option>
<?php } ?>
</select>
</div>
</div>
</div>
</th>
<th>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label class="display-block text-semibold"> สถานที่ท่องเที่ยว</label>
<select id="selTravel" name="travel_id[]" class="select-search"><option value="">กรุณาเลือกจังหวัด</option></select>
</div>
</div>
</div>
</div>
</th>
<th>
</th>
</tr>
<tr><td><center>รายการที่เพิ่ม</center></td></tr>
</thead>
<tbody>
</tbody>
</table>
<div class="row">
<div class="form-group">
<div class="col-md-6">
<button type="button" id="btnP">เพิ่มรายการ</button>
</div>
</div>
</div>
FORM INSERT
<?php
session_start();
//PUT THIS HEADER ON TOP OF EACH UNIQUE PAGE
if(!isset($_SESSION['id_user'])){
header("location:index.php");
}
include_once('config.php');
$id_user = $_SESSION['id_user'];
$rn_first_name = $_POST['rn_first_name'];
$rn_last_name = $_POST['rn_last_name'];
$rn_gostart = $_POST['rn_gostart'];
$rn_endstart = $_POST['rn_endstart'];
$time_gostart = $_POST['time_gostart'];
$time_endstart = $_POST['time_endstart'];
$rn_tel = $_POST['rn_tel'];
$rn_amount = $_POST['rn_amount'];
$rn_svan = $_POST['rn_svan'];
$rn_destination = $_POST['rn_destination'];
$id_invoice = $_POST['id_invoice'];
$Status = $_POST['Status'];
$vn_dtial = $_POST['vn_dtial'];
$rn_place = $_POST['rn_place'];
$travellist_id = $_POST['travellist_id'];
$province_id = $_POST['province_id'];
$travel_id = $_POST['travel_id'];
$total = $_POST['total'];
// function date
$date_go = "$rn_gostart"; //กำหนดค้นวันที่เริ่ม
$date_end = "$rn_endstart"; //กำหนดค้นวันที่กลับ
$datetime1 = new DateTime($date_go);
$datetime2 = new DateTime($date_end);
$datetotal = $datetime1->diff($datetime2);
$total= $datetotal->format('%a') * 1800; //ผลการคำนวณ
$date = "$rn_gostart"; //กำหนดค้นวันที่
$result = mysqli_query($mysqli,"select * from vn_rent where rn_gostart = '$date'");
$ckd = mysqli_num_rows($result);
if($ckd >= 3){
$msg = "<div class='alert alert-danger'>
<span class='glyphicon glyphicon-info-sign'></span> วันที่จองเต็มแล้ว
</div>";
}else{
// ส่วนของการ insert
$sql = "INSERT INTO vn_rent (id_user,rn_first_name,rn_last_name,rn_gostart,rn_endstart,time_gostart,time_endstart,rn_tel,rn_amount,rn_svan,Status,vn_dtial,rn_place,rn_destination,total)
VALUES ('$id_user', '$rn_first_name',' $rn_last_name ','$rn_gostart','$rn_endstart','$time_gostart','$time_endstart','$rn_tel','$rn_amount','$rn_svan','$Status','$vn_dtial','$rn_place','$rn_destination','$total')";
//คำสั่ง insert 2 ตาราง ที่ส่งค่าไปอีกตารางแล้วนำกลับมาอัปเดท
if ($mysqli->query($sql) === TRUE) {
$id_van = $mysqli->insert_id;
$mysqli->query("INSERT INTO invoice
(id_user,id_van)
VALUE($id_user, $id_van)");
$id_invoice = $mysqli->insert_id;
$mysqli->query("UPDATE vn_rent
SET id_invoice = '$id_invoice'
WHERE id_van = $id_van");
$msg = "<div class ='alert alert-success alert-styled-left alert-arrow-left alert-bordered'>
จองรถตู้สำเร็จ โปรดรอการตอบรับจากทางเจ้าหน้าที่</p> เลขที่รายการจอง <span class='text-warning'>".$id_van."</span> เลขที่ใบเสร็จ <span class='text-warning'>".$id_invoice."</span>
</div>";
header("refresh:5; url=history_booking.php");
}
else {
echo "Error: " . $sql . "<br>" . $mysqli->error;
}
}
$mysqli->close();
?>
To put that into multiple records from select into the table travel_list
multiple records from select

Update statement not working properly and changes the other records

I'm wondering why my update statement changes the venue_type of all the other records whenever I saved the edited record.
Been working on this update statement for quite sometime now and I just can't get it to work. It would be great if you guys could help me on this.
Thanks for the help! :)
<body>
<head>
<script src="js/jquery.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/smoothscroll.js"></script>
<script src="js/resetOnClick.js"></script>
<link href="css/bootstrap.min.css" rel="stylesheet"/>
<link href="css/styles.css" rel="stylesheet"/>
<link href="css/notifbox.css" rel="stylesheet"/>
</head>
<center><label class="control-label" style="font-size:30px">Reservation</label></center>
<center><label class="control-label" style="font-size:15px">Edit Record</label></center>
<br/>
<br/>
<?php
$id = isset($_GET['id'])? $_GET['id'] : "";
include('config/config1.php');
$sel = "SELECT idReservation, venue.venue_type, reservation.reservation_date, reservation.reservation_time
FROM venue
INNER JOIN reservation ON reservation.Venue_idVenue = venue.idVenue where idReservation = '$id';";
$rsvtn = isset($_POST['idReservation']);
$query = mysqli_query($conn,$sel);
while($detail = mysqli_fetch_array($query))
{
$rid = $detail['idReservation'];
$ven = $detail['venue_type'];
$res_d = $detail['reservation_date'];
$res_t = $detail['reservation_time'];
?>
<form class="form-horizontal form-label-left" method="post">
<div class="form-group">
<!--BACK Button-->
Back
<!--BACK Button-->
</div>
<!--<input type="hidden" name="submitted" value="true"/>-->
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12">Venue<span class="required">*</span></label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input id="venue_type" data-content="<?php echo $ven;?>" class="form-control col-md-7 col-xs-12" name="venue_type" placeholder="Venue" required="required" type="text" value="<?php echo $ven;?>">
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Reservation Date<span class="required">*</span>
</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input id="reservation_date" data-content="<?php echo $res_d;?>" class="form-control col-md-7 col-xs-12" name="reservation_date" placeholder="Reservation Date" required="required" type="date" value="<?php echo $res_d;?>">
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Reservation Time<span class="required">*</span></label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input id="reservation_time" data-content="<?php echo $res_t;?>" class="form-control col-md-7 col-xs-12" name="reservation_time" placeholder="Reservation Time" required="required" type="time" value="<?php echo $res_t;?>">
</div>
</div>
<div class="ln_solid"></div>
<div class="form-group">
<div class="col-md-6 col-md-offset-3">
<input type="hidden" name="updRsvtn" value="<?php echo $detail['idReservation'];?>">
<input type="submit" class="btn btn-primary submits" value="Save Edited" onClick="Reservation Records.php" >
</div>
</div>
<?php
}
?>
<?php
if(isset($_POST['updRsvtn']))
{
include('config/config1.php');
$ven = $_POST['venue_type'];
$res_d = $_POST['reservation_date'];
$res_t = $_POST['reservation_time'];
if(!mysqli_query($conn,"UPDATE reservation, venue SET venue_type = '$ven', reservation_date = '$res_d', reservation_time = '$res_t' WHERE idReservation = '$id'"))
{
echo "Not Queried: Wrong variables !";
}
else
{
header("Location: Reservation Records.php");
}
mysqli_close($conn);
}
?>
</form>
<table class = "notif pos">
<thead>
<tr>
<th><center/><b>*Old Record</b></th>
</tr>
</thead>
<tbody>
<tr>
<td><center/><b>Venue: <?php echo $ven;?></td>
</tr>
<tr>
<td><center/><b>Reservation Date: <?php echo $res_d;?></td>
</tr>
<tr>
<td><center/><b>Reservation Time: <?php echo $res_t;?></td>
</tr>
</tbody>
</table>
</body>
if its not working that means your their is not value in
$_GET['id']. then $id is having blank value that's why your query
update for all rows.
if(isset($_POST['updRsvtn']))
{
$id = isset($_GET['id'])? $_GET['id'] : "";
$ven = $_POST['venue_type'];
$res_d = $_POST['reservation_date'];
$res_t = $_POST['reservation_time'];
if(!mysqli_query($conn,"UPDATE reservation, venue SET
venue_type = '$ven', reservation_date = '$res_d',
reservation_time = '$res_t' WHERE idReservation = '$id'"))
{
echo "Not Queried: Wrong variables !";
}
else
{
header("Location: Reservation Records.php");
}
mysqli_close($conn);
}
You could try JOIN in your query
UPDATE reservation t1
JOIN venue t2 ON (t1.Venue_idVenue = t2.idVenue)
SET t1.reservation_date = '$res_d',
t1.reservation_time = '$rest_t',
t2.venue_type = '$ven'
WHERE t1.idReservation = '$id'"

Categories