Dynamic dropdown list with ajax,sql and php - php

I get a dynamic dropdown by combining config.php, index.php and ajax.php but when i modify the code and use it in another file which include the files config.php, sales.php and ajax.php i don't get the dropdown.
i have 2 folders folder_1 contains config.php, index.php and ajax.php this gives the desired dropdown list i wanted.
but in folder_2 i have config.php,sales.php and ajax.php but i did't get the dropdown.
I copy paste the exact code from folder_1 to folder_2 but the code is not working.
config.php
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<?php
$con=mysqli_connect("localhost","root","","db_cafeteria");
?>
</body>
</html>
index.php
<html>
<head>
<?php include "config.php"; ?>
<script type="text/javascript" src='js/jquery.min.js'></script>
<script>
$(document).ready(function(){
$('#category').change(function(){
var categoryid = $(this).val();
$('#food').find('option').not(':first').remove();
// AJAX request
$.ajax({
url: 'ajax.php',
type: 'post',
data: { categoryid: categoryid},
dataType: 'json',
success: function(response){
var len = response.length;
for( var i = 0; i<len; i++){
var id = response[i]['id'];
var name = response[i]['name'];
$("#food").append("<option value='"+id+"'>"+name+"</option>");
}
}
});
});
});
</script>
</head>
<body>
<table>
<tr>
<td>category</td>
<td>
<!-- Country dropdown -->
<select id='category' >
<option value="" >---Select---</option>
<?php
## Fetch countries
$sql=mysqli_query($con,"SELECT * FROM tbl_category ORDER BY categoryname");
while($row=mysqli_fetch_assoc($sql))
{
echo "<option value='".$row['category_id']."'>".$row['categoryname']."</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td>food</td>
<td>
<select id='food' >
<option value="" >---Select---</option>
</select>
</td>
</tr>
</table>
</body>
</html>
sales.php
<?php
include("header.php");
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<script type="text/javascript" src='js/jquery.min.js'></script>
<script>
$(document).ready(function(){
$('#category').change(function(){
var categoryid = $(this).val();
$('#food').find('option').not(':first').remove();
// AJAX request
$.ajax({
url: 'ajax.php',
type: 'post',
data: {categoryid: categoryid},
dataType: 'json',
success: function(response){
var len = response.length;
if( len >0 ){
$("#food").empty();
$("#food").html('<option value="">---select---</option>');
for( var i = 0; i<len; i++){
var id = response[i]['id'];
var name = response[i]['name'];
$("#food").append("<option value='"+id+"'>"+name+"</option>");
}
}
else
{
$('#food').html('<option value="">No food available</option>');
}
}
});
});
});
</script>
</head>
<body>
<?php
include("config.php");
?>
<form action="stock_reg_action.php" method="post" enctype="multipart/form-data">
<div class="container" style="margin-left:106px; margin-bottom:10%;padding-left:130px; box-shadow: 2px 2px 10px #1b93e1; border-radius: 4px; top: 14px; padding-top: 5%;">
<h2 style="text-align: center;margin-top: 6%;font-family: fantasy; padding-right:13%"> ADD PRODUCT STOCK</h2>
<br>
<div class="row">
<div class="col-md-3" style="text-align:right; padding-top:8px;">
<label>Date</label>
</div>
<div class="col-md-6">
<input type="date" class="form-control" name="stock_date" style="width:500px;" required autofocus>
</div>
</div>
<br>
<div class="row">
<div class="col-md-3" style="text-align:right; padding-top:8px;">
<label>Category</label>
</div>
<div class="col-md-6">
<select required name="category_id" id="category" class="form-control" style="width:500px;" required autofocus>
</div>
</div>
<br>
<div class="row">
<div class="col-md-6">
<option selected disabled value="">---select---</option>
<?php
$sql=mysqli_query($con,"SELECT * FROM tbl_category ORDER BY categoryname");
while($row=mysqli_fetch_assoc($sql))
{
echo "<option value='".$row['category_id']."'>".$row['categoryname']."</option>";
}
?>
</select>
</div>
</div>
<br>
<div class="row">
<div class="col-md-3" style="text-align:right; padding-top:8px;">
<label>Food</label>
</div>
<div class="col-md-6">
<select name="food_id" id="food" class="form-control" style="width:500px;" required autofocus>
<option selected disabled value="">---select---</option>
</select>
</div>
</div>
<br>
<div class="row">
<div class="col-md-3" style="text-align:right">
<label>Stock Status</label>
</div>
<label style="margin-left:15px">
<input type="radio" name="radio" value="1" />
<span>ADD</span>
</label>
<label style="margin-left:30px">
<input type="radio" name="radio" value="0" />
<span>REMOVE</span>
</label>
</div>
<br>
<div class="row">
<div class="col-md-3" style="text-align:right; padding-top:8px;">
<label>Quantity</label>
</div>
<div class="col-md-6">
<input type="text" class="form-control" name="quantity" style="width:500px;" placeholder="Enter Quantity" required autofocus>
</div>
</div>
<br>
<div class="row">
<div class="col-md-3" style="text-align:right; padding-top:8px;">
<label>Description</label>
</div>
<div class="col-md-6">
<input type="textarea" class="form-control" name="stock_description" style="width:500px;" placeholder="Enter Description" required autofocus>
</div>
</div>
<br>
<div class="row">
<input type="submit" name="submit" value="SAVE" class="btn btn-primary" style="margin-left:38%">
</div>
<br>
</div>
</form>
</body>
</html>
<?php
include("footer.php");
?>
ajax.php
<?php
include "config.php";
// Fetch food list by categoryid
$categoryid = $_POST['categoryid'];
$response = array();
$sql=mysqli_query($con,"SELECT * FROM tbl_food WHERE category_id='".$_POST["categoryid"]."' ORDER BY food_name");
while($row=mysqli_fetch_array($sql))
{
$id=$row["food_id"];
$name=$row["food_name"];
$response[] = array("id" => $id, "name" => $name);
}
echo json_encode($response);
exit;
?>

Related

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

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 =)

how can I use dependent dropdown lists in php bootstrap modal?

I want to implement the dropdown lists in bootstrap modal.
I have already a demo code but I don't know how to implement it in the bootstrap modal.
In The bootstrap modal form will be open with 2 dependent dropdowns and after submitting the values will be saved to database.
Thanks a lot in advance.
index.php
<!DOCTYPE html>
<html>
<head>
<title>PHP - dependent dropdown list</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="http://demo.itsolutionstuff.com/plugin/bootstrap-3.min.css">
</head>
<body>
<div class="container">
<div class="panel panel-default">
<div class="panel-heading">Select State and get bellow Related City</div>
<div class="panel-body">
<div class="form-group">
<label for="title">Select State:</label>
<select name="state" class="form-control">
<option value="">--- Select State ---</option>
<?php
require('db_config.php');
$sql = "SELECT * FROM demo_state";
$result = $mysqli->query($sql);
while($row = $result->fetch_assoc()){
echo "<option value='".$row['id']."'>".$row['name']."</option>";
}
?>
</select>
</div>
<div class="form-group">
<label for="title">Select City:</label>
<select name="city" class="form-control" style="width:350px">
</select>
</div>
</div>
</div>
</div>
<script>
$( "select[name='state']" ).change(function () {
var stateID = $(this).val();
if(stateID) {
$.ajax({
url: "ajaxpro.php",
dataType: 'Json',
data: {'id':stateID},
success: function(data) {
$('select[name="city"]').empty();
$.each(data, function(key, value) {
$('select[name="city"]').append('<option value="'+ key +'">'+ value +'</option>');
});
}
});
}else{
$('select[name="city"]').empty();
}
});
</script>
</body>
</html>
ajaxpro.php
<?php
require('db_config.php');
$sql = "SELECT * FROM demo_cities
WHERE state_id LIKE '%".$_GET['id']."%'";
$result = $mysqli->query($sql);
$json = [];
while($row = $result->fetch_assoc()){
$json[$row['id']] = $row['name'];
}
echo json_encode($json);
?>
please help me.. thanks a lot.
index.php
<?php
include("db/db.php");
$select_country = "SELECT country_id,country_name from country";
$result_country = mysqli_query($con,$select_country);
?>
<!DOCTYPE html>
<html>
<head>
<title>ADDRESS FORM</title>
<script type="text/javascript" src="js/jquery.3.2.1.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<script type="text/javascript">
$(document).on("click","#reg",function(){
$(".modal-title").html("Registration Form");
$("#myModal").modal({backdrop: "static", keyboard: false});
});
$(document).on("click","#adddata",function(e){
var state = parseInt($("#selectstate").val());
var country = parseInt($("#selectcountry").val());
console.log(state+country);
$.ajax({
type : 'POST',
url : 'insert_all.php?action=ins_std',
data : {'state': state,'country' : country},
dataType : "JSON",
success:function(feedback){
if(feedback=="yes"){
$(".alert2").html("<b style='color:green;'>Recored Successfully Added </b>");
$("#std-form")[0].reset();
$("#myModal").modal('hide');
$(".has-error").removeClass("has-error");
$(".alert2").show().delay(5000).fadeOut();
} else{
$("#alert").show();
$(".alert1").html("<b style='color:red;'> Cant Add Recored </b>");
$(".alert1").show().delay(5000).fadeOut();
}
}
});
});
$(document).on("change","#selectcountry",function(){
var c_id = parseInt($("#selectcountry").val());
console.log(c_id);
$.ajax({
type : 'POST',
url : 'get_asc.php',
data : {'country_id' : c_id},
success : function(feedback)
{
$("#selectstate").html(feedback);
}
});
});
</script>
</head>
<body>
<div class="container">
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" id="btn_close">×</button>
<h4 class="modal-title"></h4><div class="alert1" id="alert"></div>
</div>
<div class="modal-body">
<form name="add" method="post" id="std-form">
<div class="form-group item-required" id="selectcountryerror">
<label for="country">Country</label>
<select id="selectcountry" name="selectcountry" class="form-control input-value">
<option value="">Select Country</option>
<?php foreach ($result_country as $country) { ?>
<option value="<?php echo $country["country_id"]?>"><?php echo $country["country_name"]?></option>
<?php } ?>
</select>
</div>
<div class="form-group item-required" id="selectstateerror">
<label for="state">State</label>
<select id="selectstate" name="selectstate" class="form-control input-value">
<option value="">Select State</option>
</select>
</div>
<div class="form-group" id="areaerror">
<button type="button" class="btn btn-default" id="adddata" >Add Data</button>
<button type="button" class="btn btn-default" id="savedata" data-dismiss="">Save Data</button><br>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default btnclose" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<center>
<button type="button" class="btn btn-info btn-md" id="reg" >Click Here For Registration Form</button>
</center>
</div>
</body>
get_asc.php
**insert/select page**
<?php
include("db/db.php");
if(isset($_POST['country_id']))
{
$select_state = "SELECT state_id,c_id,state_name from state where c_id = '".$_POST['country_id']."' ";
$result_state = mysqli_query($con,$select_state);
?>
<option value="">Select State</option>
<?php
foreach($result_state as $state) {
?>
<option value="<?php echo $state["state_id"]; ?>"><?php echo $state["state_name"]; ?></option>
<?php
}
}
elseif($_REQUEST['action']=="ins_std")
{
$country = mysqli_real_escape_string($con,$_POST['country']);
$state = mysqli_real_escape_string($con,$_POST['state']);
$insert_std = "INSERT into student (s_id,c_id) values ('".$state."','".$country."')";
$res_std=mysqli_query($con,$insert_std);
if($res_std){
echo json_encode("yes");
}else{
echo json_encode("fail");
}
}
?>
Just add bootstrap modal instead of panel and a button for open that modal and add your form in a modal body.
Your code of index.php looks like below:
<!DOCTYPE html>
<html>
<head>
<title>PHP - dependent dropdown list</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>
</head>
<body>
<div class="container">
<h2>Modal Example</h2>
<!-- Trigger the modal with a button -->
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Select State and get bellow Related City</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label for="title">Select State:</label>
<select name="state" class="form-control">
<option value="">--- Select State ---</option>
<?php
require('db_config.php');
$sql = "SELECT * FROM demo_state";
$result = $mysqli->query($sql);
while($row = $result->fetch_assoc()){
echo "<option value='".$row['id']."'>".$row['name']."</option>";
}
?>
</select>
</div>
<div class="form-group">
<label for="title">Select City:</label>
<select name="city" class="form-control" style="width:350px">
</select>
</div>
<button type="submit">submit</button>
</div>
</div>
</div>
</div>
<script>
$( "select[name='state']" ).change(function () {
var stateID = $(this).val();
if(stateID) {
$.ajax({
url: "ajaxpro.php",
dataType: 'Json',
data: {'id':stateID},
success: function(data) {
$('select[name="city"]').empty();
$.each(data, function(key, value) {
$('select[name="city"]').append('<option value="'+ key +'">'+ value +'</option>');
});
}
});
}else{
$('select[name="city"]').empty();
}
});
</script>
</div>
</body>
</html>

login page php code not working on cpanel blank page comes after succefull login

The code is working perfectly on localhost xampp server but not working on Cpanel I think sesion_start command not working. If i login using wrong password then it shows an error its mean php code in LoinPage.php
wroks but when i enter correct username and password it will show blank page instead of taking me to AdminDashboard.php
LoginPage.php
<!DOCTYPE html>
<html >
<head>
<meta charset="UTF-8">
<title>Seza Admin Login</title>
<link rel="stylesheet" href="css/loginStyle.css">
</head>
<body>
<?php include("connection.php");
error_reporting(E_ALL);
$msg=null;
if(isset($_POST['login']) && $_POST['login']=='ok')
{
$username =$_POST['username'];
$password = $_POST['password'];
$selectuser = mysqli_query($conn,"select * from admins where USERNAME='".$username."' and PASSWORD ='".$password."'") or die(mysqli_error($conn));
$no_users = mysqli_num_rows($selectuser);
if($no_users>0)
{
$fetch_user = mysqli_fetch_array($selectuser);
$_SESSION['adminid']= $fetch_user['AID'];
alert("success");
header("location:AdminDashboard.php");
}
else{
$msg = "The username or password is invalid";
}
}
else{
if(isset($_POST['login']) && $_POST['login']=='ok')
{
echo"invalid";
}
}
?>
<div class="site_wrapper">
<form method="post" id="additem-form" >
<input type="hidden" id="login" name="login" value="ok" />
<div class="login">
<div class="login-screen">
<div class="app-title">
<h1>SezaPharma</h1>
<h3>ADMIN LOGIN</h3>
</div>
<div class="login-form">
<div class="control-group">
<input type="text" class="login-field" value="" placeholder="username" id="username" name="username">
<label class="login-field-icon fui-user" for="login-name"></label>
</div>
<div class="control-group">
<input type="password" class="login-field" value="" placeholder="password" id="password" name="password">
<label class="login-field-icon fui-lock" for="login-pass"></label>
</div>
<button class="btn btn-primary btn-large btn-block" type="submit" value="login" >login</button>
<a class="login-link" onClick="alertRset()" href="">Lost ? Reset your password?</a>
<div style="color:#FF0004">
<?php
if(isset($msg) && $msg!="")
{ ?>
<div class="alert-danger"><?php echo $msg; ?></div>
<?php }
?></div>
</div>
</div>
</div>
</form>
<script>
function alertRset() {
var txt;
if (confirm("It will Reset username and password to default.") == true) {
window.close();
window.open("resetadmin.php");
} else {
txt = "You pressed Cancel!";
}
document.getElementById("demo").innerHTML = txt;
}
</script>`enter code here`
</body>
</html>
AdminDashboard.php
<!DOCTYPE html>
<html>
<head>
</style>
</head>
<body>
<?php include("connection.php");
error_reporting(E_ALL);
if (isset($_SESSION['adminid'])) {
?>
<div class="dashboard">
<div class="tab">
<button class="tablinks" onclick="openCity(event, 'London')" id="defaultOpen">All Products</button>
<button class="tablinks" onclick="openCity(event, 'Paris')">Add New Product</button>
<button class="tablinks" onclick="openCity(event, 'Tokyo')">Setting</button>
<a href="logout.php" ><button class="tablinks" onclick="openCity(event, 'Tokyo')" >Loggout</button></a>
</div>
<div id="London" class="tabcontent" style="overflow:auto">
<div class="site_wrapper" >
<div class="clearfix margin_top10"></div>
<div class="works01" >
<div class="container" >
<div id="grid-container" class="cbp-l-grid-fullWidth" style="overflow:visible;">
<?php
$select_post=mysqli_query($conn,"select * from products ORDER BY PID desc") or die(mysqli_error());
while($post=mysqli_fetch_array($select_post))
{
?>
<div class="cbp-item <?php echo $post['PTYPE'];?>">
<div class="cbp-caption">
<div class="cbp-caption-defaultWrap">
<img style="width:100%; height:200px;" src="UploadedImage/<?php echo $post['PIMAGELOC'];?>" alt="">
</div>
<div class="cbp-caption-activeWrap">
<div class="cbp-l-caption-alignCenter">
<div class="cbp-l-caption-body">
<h3><?php echo $post['PNAME'];?></h3>
<br />
Edit
Delete
</div>
</div>
</div>
</div>
</div><!-- end item -->
<?php
}
?>
</div>
</div>
</div><!-- end works section -->
Scroll<!-- end scroll to top of the page-->
</div>
</div>
<div id="Paris" class="tabcontent">
<form action="add_item.php" method="post" enctype="multipart/form-data" onsubmit="return validateForm()" id="additem-form" name="additem-form">
<div class="contactcontainer">
<header>
<h1>Add new Product</h1>
</header>
<table width="100%" align="center">
<tr>
<td colspan="2">
<input style="width:74%" placeholder="Product Name" type="text" id="pname" name="pname">
</td>
</tr>
<tr>
<td colspan="2">
<select class="select" style=" width:74%;" name="cat" id="cat">
<option value="Category" selected="selected">Product Category</option>
<option value="livestock" > livestock Products</option>
<option value="Poultry">Poultry Products</option>
</select>
</td>
</tr>
<tr>
<td colspan="2" >
<div style="border:dashed; width:75%;" align="center">
<h4>Choose Product Picture</h4>
<input type="file" id="pimage" name="pimage" class="input-file" title="upload Photo / video" />
</div>
</td>
</tr>
<tr>
<td>
<select class="select" style=" width:55%;" id="ptype" name="ptype">
<option value="Type">Product Type</option>
<option value="Injections">Injections</option>
<option value="Anthilmentics">Anthilmentics</option>
<option value="Natural">Natural Products</option>
</select>
</td>
<td>
<select class="select" id="availability" style=" width:55%;" name="availability">
<option value="Availability">Availability</option>
<option value="yes">Yes</option>
<option value="no">No</option>
</select>
</td>
</tr>
<tr>
<td colspan="2">
<input style="width:74%" class="email" placeholder="Full Farmula with quantity" type="text" id="pfarmula" name="pfarmula">
</td>
</tr>
<tr>
<td colspan="2">
<textarea style="width:74%" placeholder="Product Description" id="pdesc" name="pdesc"></textarea>
</td>
</tr>
<tr>
<td colspan="2" >
<div style="width:74%" align="center">
<footer>
<button style="width:20%" id="addbtn" name="addbtn" >Add</button>
</footer>
</div>
</td>
</tr>
</table>
</div>
</form>
</div>
<div id="Tokyo" class="tabcontent">
<h3>Tokyo</h3>
<p>Tokyo is the capital of Japan.</p>
</div>
</div> <!--end of tabs-->
<script>
function validateForm()
{
var a=document.forms["additem-form"]["availability"].value;
var b=document.forms["additem-form"]["pname"].value;
var c=document.forms["additem-form"]["cat"].value;
var d=document.forms["additem-form"]["ptype"].value;
if (a=="Availability" || b=="" || c=="Category" || d=="Type")
{
alert("Please Fill All Required Field");
return false;
}
}
function openCity(evt, cityName) {
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
document.getElementById(cityName).style.display = "block";
evt.currentTarget.className += " active";
}
// Get the element with id="defaultOpen" and click on it
document.getElementById("defaultOpen").click();
</script>
<!-- ######### JS FILES ######### -->
<!-- get jQuery used for the theme -->
<script type="text/javascript" src="js/universal/jquery.js"></script>
<script src="js/style-switcher/styleselector.js"></script>
<script src="js/animations/js/animations.min.js" type="text/javascript"></script>
<script src="js/mainmenu/bootstrap.min.js"></script>
<script src="js/mainmenu/customeUI.js"></script>
<script src="js/scrolltotop/totop.js" type="text/javascript"></script>
<script type="text/javascript" src="js/mainmenu/sticky.js"></script>
<script type="text/javascript" src="js/mainmenu/modernizr.custom.75180.js"></script>
<script type="text/javascript" src="js/cubeportfolio/jquery.cubeportfolio.min.js"></script>
<script type="text/javascript" src="js/cubeportfolio/main31.js"></script>
<?php } else{ echo " You mus Loggedin to acces this page"; } ?>
</body>
</html>
connection.php
<?php
session_start();
// Create connection
$conn = mysqli_connect("localhost", "username","password", "sezaphar_sezapharmadb") or die($conn->connect_error);
?>
You have a bug in the code.
You need to echo the alert("success") before header("location:AdminDashboard.php"); in LoginPage.php
Here's the code:
echo "<script>alert('success');</script>";

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

ajax and a form with post method

I have a problem with a form that is used to insert data into a table, I need it to show a message if the data is inserted correctly or not. by the way, the actual code is not inserting anything to the table, but if I use directly the php file used to insert it, it works.
this is the file with the form and the script:
registrarrack.php
<?php
include('conexion.php');
session_start();
?>
<html>
<head>
<title>Inicio</title>
<link rel="stylesheet" type="text/css" href="style/stylef.css">
<link rel="stylesheet" type="text/css" href="style/style.css">
<script src="js/jquery-1.12.4.js"></script>
<script> function myFunction() {
document.getElementsByClassName("topnav")[0].classList.toggle("responsive");
}
function justNumbers(e)
{
var keynum = window.event ? window.event.keyCode : e.which;
if ((keynum == 8))
return true;
return /\d/.test(String.fromCharCode(keynum));
}
function showContent() {
element = document.getElementById("content");
check = document.getElementById("check");
if (check.checked) {
element.style.display='block';
}
else {
element.style.display='none';
}
}
</script>
</head>
<!-- _________________________________________________________________AJAX Script___________________________________________________________________________-->
<script>
function Validar(Noserie, WO, Locacion, Modelo)
{
$.ajax({
url: "registrarrackbackend.php",
type: "POST",
data: "Noserie="+Noserie+"&WO="+WO+"&Locacion="+Locacion+"&Modelo="+Modelo,
success: function(resp){
$('#resultado').html(resp)
}
});
}</script>
<!-- _________________________________________________________________End of AJAX Script___________________________________________________________________________-->
<body class="desarroll">
<header>
<div class="grupo">
<div class="caja">
<center><nav>
<ul class="topnav">
<li>| Inicio |</li>
<li>| Estatus |</li>
<li>| Buscar nodo |</li>
<li>| Buscar rack |</li>
<li>| Estadisticas |</li>
<?php if(isset($_SESSION['Nombrers'])){ echo '<li>| Cerrar Sesion |</li>';}else{echo '<li>| Iniciar Sesion |</li>';}?>
<li class="icon">
☰</li>
</ul>
</nav></center>
</div>
</div>
<?php if(isset($_SESSION['Nombrers'])){
echo '<center><div class="nombre" align="center">| '.$_SESSION['Nombrers'].' | '.$_SESSION['Mesamensrs'].' </div></center>';
}?>
</header>
<section>
<!-- ********************LOGIN***********************************-->
<?php
$query = mysqli_query($enlace, "SELECT Numero FROM mesas WHERE EnUso = '0'");
if(!isset($_SESSION['Nombrers'])){
echo '<center> <div id="modal">
<div class="modal-content ">
<div class="header">
<h2>Iniciar sesión</h2>
<center><hr width="150" align="center"/></center>
</div>
<div class="copy">
<div class="grupo">
<div class="caja">
<form method="post" action="login.php" class="login">
<label style="color:#1BBC9B; font-weight:bold;">
<input type="checkbox" style="width:0px; display:relative;" name="check" id="check" value="1" onchange="javascript:showContent()" >¿Técnico de reparación?</label><br>
<div id="content" style="display: none;">
<b>Mesas disponibles :
<input type="radio" name="mesa" style="width:0px; " value="0" checked="checked"> ';
while ($datos=mysqli_fetch_row($query) ) {
echo '<label><input type="radio" name="mesa" value="'.$datos[0].'" style="color:black; width:30px;">'.$datos[0].'</label> ';
}
echo '</b>
</div>
<input type="text" name="NoReloj" placeholder="Número de reloj" required maxlength="5" onkeypress="return justNumbers(event);">
<input type="password" name="Pass" placeholder="Contraseña" required>
<input type="hidden" name="Url" value="index.php#">
</script>
<button class="btn1">Aceptar</button>
<input class="btn2" type="button" value="Cerrar" onClick="window.location.href=\'#\'">
</form>
</div>
</div>
</div>
</div>
<div class="overlay"></div>
</div></center>'
;
}
echo '<center> <div id="modalmesa">
<div class="modal-content ">
<div class="header">
<h2>Elegir mesa</h2>
<center><hr width="150" align="center"/></center>
</div>
<div class="copy">
<div class="grupo">
<div class="caja">
<form method="post" action="elegirmesa.php" class="login">
<div id="resultado"></div>
<input type="hidden" name="Url" value="index.php#">
</script>
<button class="btn1">Aceptar</button>
</form>
</div>
</div>
</div>
</div>
<div class="overlay"></div>
</div></center>'
;
?>
<!-- _________________________________________________________________Form___________________________________________________________________________-->
</section>
<center>
<?php $query = mysqli_query($enlace, "SELECT Nombre FROM familia"); ?>
<div class="grupo-centar">
<div class="caja">
<br><br>
<h2>Registrar rack</h2><br>
<div id="resultado"></div>
<table class="tablaregistro">
<tr>
<form class="RegistroR" method="POST" action="return false" onsubmit="return false" id="formregistro">
<td><input type="text" name="Noserie" id="Noserie" placeholder="Número de serie" required form="formregistro" maxlength="10" pattern=".{10,}" ></td>
</tr>
<tr>
<td><input type="text" name="WO" id="WO" placeholder="WO" required form="formregistro" maxlength="9" pattern=".{9,}"></td>
</tr>
<tr>
<td><input type="text" name="Locacion" id="Locacion" placeholder="Locación: TRXX-XX" required form="formregistro" maxlength="8" pattern=".{7,}"></td>
</tr>
<tr>
<td><Select name="Modelo" id="Modelo" required form="formregistro" placeholder="Modelo">
<option value="" disabled selected>Modelo</option>
<?php
while ($datos=mysqli_fetch_row($query) ) {
echo '<option value="'.$datos[0].'">'.$datos[0].'</option>';
}
?>
</Select></td>
</tr>
<tr>
<td><Button class="btnregistrar" form="formregistro" onclick="Validar(document.getElementById('Noserie').value, document.getElementById('WO').value, document.getElementById('Locacion').value, document.getElementById('Modelo').value);"><h1>Registrar</h1></Button></td>
</tr>
</table>
</form>
</center>
</div>
</div>
<section>
<!-- _________________________________________________________________AJAX Script___________________________________________________________________________-->
</body>
</html>
and heres the other php file:
registrarrackbackend.php
<?php
error_reporting(0);
include('conexion.php');
session_start();
$NoSerie = $_POST['Noserie'];
$Locacion = $_POST['Locacion'];
$WO = $_POST['WO'];
$Familia = $_POST['Modelo'];
$Tecnico = $_SESSION['No_Relojrs'];
$consulta=mysqli_query($enlace, "SELECT * FROM rack WHERE NoSerie= '$NoSerie'");
if($cons=mysqli_fetch_array($consulta)){
echo '<span>Error: rack is already registered</span>';
}else{
$sql2="INSERT INTO rack (NoSerie, WO, Familia, Locacion, Tecnico) VALUES ('$NoSerie','$WO' ,'$Familia','$Locacion','$Tecnico')";
if(mysqli_query($enlace, $sql2)){
//echo "<script>location.href = 'index.php'</script>";
echo '<span>rack was successfully registered</span>';
}else{echo "<span>Error updating record: " . mysqli_error($conn).'</span>';}
}
?>
I don't know what is wrong with the code, I hope you can help me please. and sorry for my bad english

Categories