MySQLi Query not working, correct Syntax? - php

Hi everyone so I have 3 tables: invoices, customers and invoice items however it does not seem to be grabbing my data, anyone have any ideas on it?
string(216) "SELECT * FROM invoices as i JOIN customers as c ON c.invoice = i.invoice JOIN invoice_items as p ON p.invoice = i.invoice WHERE i.invoice = 1000 ORDER BY i.invoice " NULL Errormessage:
From:
var_dump($query);
var_dump($resutls);
printf("Errormessage: %s\n", $mysqli->error);
QUERY:
SELECT *
FROM invoices as i
JOIN customers as c ON c.invoice = i.invoice
JOIN invoice_items as p ON p.invoice = i.invoice
WHERE i.invoice = ".$getID."
ORDER BY i.invoice
PHP
<?php
include('includes/config.php');
include('header.php');
include('functions.php');
$getID = $_GET['id'];
// Connect to the database
$mysqli = new mysqli(DATABASE_HOST, DATABASE_USER, DATABASE_PASS, DATABASE_NAME);
// output any connection error
if ($mysqli->connect_error) {
die('Error : ('.$mysqli->connect_errno .') '. $mysqli->connect_error);
}
// the query
$query = "SELECT *
FROM invoices i,customers c,invoice_items p where
c.invoice = i.invoice and p.invoice = i.invoice and
i.invoice = '".$getID."' ORDER BY i.invoice";
// mysqli select query
$results = $mysqli->query($query);
// mysqli select query
if($results) {
while($row = $results->fetch_assoc()) {
//var_dump($row['customer_name']);
$customer_name = $row['customer_name']; // customer name
$customer_email = $row['customer_email']; // customer email
$customer_address_1 = $row['customer_address_1']; // customer address
$customer_address_2 = $row['customer_address_2']; // customer address
$customer_town = $row['customer_town']; // customer town
$customer_county = $row['customer_county']; // customer county
$customer_postcode = $row['customer_postcode']; // customer postcode
$customer_phone = $row['customer_phone']; // customer phone number
//shipping
$customer_name_ship = $row['customer_name_ship']; // customer name (shipping)
$customer_address_1_ship = $row['customer_address_1_ship']; // customer address (shipping)
$customer_address_2_ship = $row['customer_address_2_ship']; // customer address (shipping)
$customer_town_ship = $row['customer_town_ship']; // customer town (shipping)
$customer_county_ship = $row['customer_county_ship']; // customer county (shipping)
$customer_postcode_ship = $row['customer_postcode_ship']; // customer postcode (shipping)
// invoice details
$invoice_number = $row['invoice_id']; // invoice number
$invoice_date = $row['invoice_date']; // invoice date
$invoice_due_date = $row['invoice_due_date']; // invoice due date
$invoice_subtotal = $row['invoice_subtotal']; // invoice sub-total
$invoice_shipping = $row['invoice_shipping']; // invoice shipping amount
$invoice_discount = $row['invoice_discount']; // invoice discount
$invoice_vat = $row['invoice_vat']; // invoice vat
$invoice_total = $row['invoice_total']; // invoice total
$invoice_notes = $row['invoice_notes']; // Invoice notes
$invoice_status = $row['invoice_status']; // Invoice status
}
}
?>
<h1>Edit Invoice (<?php echo $getID; ?>)</h1>
<hr>
<div id="response" class="alert alert-success" style="display:none;">
×
<div class="message"></div>
</div>
<form method="post" id="create_invoice">
<input type="hidden" name="action" value="create_invoice">
<div class="row">
<div class="col-xs-5">
<h1>
<img src="<?php echo COMPANY_LOGO ?>" class="img-responsive">
</h1>
</div>
<div class="col-xs-7 text-right">
<div class="row">
<div class="col-xs-9">
<h1>INVOICE</h1>
</div>
<div class="col-xs-3">
<select name="invoice_status" id="invoice_status" class="form-control">
<option value="open" <?php if($invoice_status == "open"){?>selected<?php } ?>>Open</option>
<option value="paid" <?php if($invoice_status == "paid"){?>selected<?php } ?>>Paid</option>
</select>
</div>
</div>
<div class="col-xs-4 no-padding-right">
<div class="form-group">
<div class="input-group date" id="invoice_date">
<input type="text" class="form-control required" name="invoice_date" placeholder="Select invoice date" data-date-format="<?php echo DATE_FORMAT ?>" value="<?php echo $invoice_date; ?>" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
<div class="col-xs-4">
<div class="form-group">
<div class="input-group date" id="invoice_due_date">
<input type="text" class="form-control required" name="invoice_due_date" placeholder="Select due date" data-date-format="<?php echo DATE_FORMAT ?>" value="<?php echo $invoice_due_date; ?>" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
<div class="input-group col-xs-4 float-right">
<span class="input-group-addon">#<?php echo INVOICE_PREFIX ?></span>
<input type="text" name="invoice_id" id="invoice_id" class="form-control required" placeholder="Invoice Number" aria-describedby="sizing-addon1" value="<?php echo $getID; ?>">
</div>
</div>
</div>
<div class="row">
<div class="col-xs-6">
<div class="panel panel-default">
<div class="panel-heading">
<h4>Customer Information</h4>
<div class="clear"></div>
</div>
<div class="panel-body form-group form-group-sm">
<div class="row">
<div class="col-xs-6">
<div class="form-group">
<input type="text" class="form-control margin-bottom copy-input required" name="customer_name" id="customer_name" placeholder="Enter name" tabindex="1" value="<?php echo $customer_name; ?>">
</div>
<div class="form-group">
<input type="text" class="form-control margin-bottom copy-input required" name="customer_address_1" id="customer_address_1" placeholder="Address 1" tabindex="3" value="<?php echo $customer_address_1; ?>">
</div>
<div class="form-group">
<input type="text" class="form-control margin-bottom copy-input required" name="customer_town" id="customer_town" placeholder="Town" tabindex="5" value="<?php echo $customer_town; ?>">
</div>
<div class="form-group no-margin-bottom">
<input type="text" class="form-control copy-input required" name="customer_postcode" id="customer_postcode" placeholder="Postcode" tabindex="7" value="<?php echo $customer_postcode; ?>">
</div>
</div>
<div class="col-xs-6">
<div class="input-group float-right margin-bottom">
<span class="input-group-addon">#</span>
<input type="email" class="form-control copy-input required" name="customer_email" id="customer_email" placeholder="E-mail address" aria-describedby="sizing-addon1" tabindex="2" value="<?php echo $customer_email; ?>">
</div>
<div class="form-group">
<input type="text" class="form-control margin-bottom copy-input" name="customer_address_2" id="customer_address_2" placeholder="Address 2" tabindex="4" value="<?php echo $customer_address_2; ?>">
</div>
<div class="form-group">
<input type="text" class="form-control margin-bottom copy-input required" name="customer_county" id="customer_county" placeholder="County" tabindex="6" value="<?php echo $customer_county; ?>">
</div>
<div class="form-group no-margin-bottom">
<input type="text" class="form-control required" name="customer_phone" id="invoice_phone" placeholder="Phone number" tabindex="8" value="<?php echo $customer_phone; ?>">
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-xs-6 text-right">
<div class="panel panel-default">
<div class="panel-heading">
<h4>Shipping Information</h4>
</div>
<div class="panel-body form-group form-group-sm">
<div class="row">
<div class="col-xs-6">
<div class="form-group">
<input type="text" class="form-control margin-bottom required" name="customer_name_ship" id="customer_name_ship" placeholder="Enter name" tabindex="9" value="<?php echo $customer_name_ship; ?>">
</div>
<div class="form-group">
<input type="text" class="form-control margin-bottom" name="customer_address_2_ship" id="customer_address_2_ship" placeholder="Address 2" tabindex="11" value="<?php echo $customer_address_2_ship; ?>">
</div>
<div class="form-group no-margin-bottom">
<input type="text" class="form-control required" name="customer_county_ship" id="customer_county_ship" placeholder="County" tabindex="13" value="<?php echo $customer_county_ship; ?>">
</div>
</div>
<div class="col-xs-6">
<div class="form-group">
<input type="text" class="form-control margin-bottom required" name="customer_address_1_ship" id="customer_address_1_ship" placeholder="Address 1" tabindex="10" value="<?php echo $customer_address_1_ship; ?>">
</div>
<div class="form-group">
<input type="text" class="form-control margin-bottom required" name="customer_town_ship" id="customer_town_ship" placeholder="Town" tabindex="12" value="<?php echo $customer_town_ship; ?>">
</div>
<div class="form-group no-margin-bottom">
<input type="text" class="form-control required" name="customer_postcode_ship" id="customer_postcode_ship" placeholder="Postcode" tabindex="14" value="<?php echo $customer_postcode_ship; ?>">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- / end client details section -->
<table class="table table-bordered" id="invoice_table">
<thead>
<tr>
<th width="500">
<h4><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Item</h4>
</th>
<th>
<h4>Qty</h4>
</th>
<th>
<h4>Price</h4>
</th>
<th width="300">
<h4>Discount</h4>
</th>
<th>
<h4>Sub Total</h4>
</th>
</tr>
</thead>
<tbody>
<?php
foreach($invoice_product as $key => $value) {
$item_product = $value;
// $item_description = $_POST['invoice_product_desc'][$key];
$item_qty = $row['invoice_product_qty'][$key];
$item_price = $row['invoice_product_price'][$key];
$item_discount = $row['invoice_product_discount'][$key];
$item_subtotal = $row['invoice_product_sub'][$key];
?>
<tr>
<td>
<div class="form-group form-group-sm no-margin-bottom">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
<input type="text" class="form-control form-group-sm item-input invoice_product" name="invoice_product[]" placeholder="Enter item title and / or description" value="<?php echo $item_product; ?>">
<p class="item-select">or select an item</p>
</div>
</td>
<td class="text-right">
<div class="form-group form-group-sm no-margin-bottom">
<input type="text" class="form-control calculate" name="invoice_product_qty[]" value="1" value="<?php echo $item_qty; ?>">
</div>
</td>
<td class="text-right">
<div class="input-group input-group-sm no-margin-bottom">
<span class="input-group-addon"><?php echo CURRENCY ?></span>
<input type="text" class="form-control calculate invoice_product_price required" name="invoice_product_price[]" aria-describedby="sizing-addon1" placeholder="0.00" value="<?php echo $item_price; ?>">
</div>
</td>
<td class="text-right">
<div class="form-group form-group-sm no-margin-bottom">
<input type="text" class="form-control calculate" name="invoice_product_discount[]" placeholder="Enter % or value (ex: 10% or 10.50)" value="<?php echo $item_discount; ?>">
</div>
</td>
<td class="text-right">
<div class="input-group input-group-sm">
<span class="input-group-addon"><?php echo CURRENCY ?></span>
<input type="text" class="form-control calculate-sub" name="invoice_product_sub[]" id="invoice_product_sub" value="0.00" aria-describedby="sizing-addon1" value="<?php echo $item_subtotal; ?>" disabled>
</div>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<div id="invoice_totals" class="padding-right row text-right">
<div class="col-xs-6">
<div class="input-group form-group-sm textarea no-margin-bottom">
<textarea class-"form-control" name="invoice_notes" placeholder="Please enter any order notes here." value="<?php echo $invoice_notes; ?>"></textarea>
</div>
</div>
<div class="col-xs-6 no-padding-right">
<div class="row">
<div class="col-xs-3 col-xs-offset-6">
<strong>Sub Total:</strong>
</div>
<div class="col-xs-3">
<?php echo CURRENCY ?><span class="invoice-sub-total"> <?php echo $invoice_subtotal; ?></span>
<input type="hidden" name="invoice_subtotal" id="invoice_subtotal" value="<?php echo $invoice_subtotal; ?>">
</div>
</div>
<div class="row">
<div class="col-xs-3 col-xs-offset-6">
<strong>Discount:</strong>
</div>
<div class="col-xs-3">
<?php echo CURRENCY ?><span class="invoice-discount"> <?php echo $invoice_discount; ?></span>
<input type="hidden" name="invoice_discount" id="invoice_discount" value="<?php echo $invoice_discount; ?>">
</div>
</div>
<div class="row">
<div class="col-xs-3 col-xs-offset-6">
<strong class="shipping">Shipping:</strong>
</div>
<div class="col-xs-3">
<div class="input-group input-group-sm">
<span class="input-group-addon"><?php echo CURRENCY ?></span>
<input type="text" class="form-control calculate shipping" name="invoice_shipping" aria-describedby="sizing-addon1" placeholder="0.00" value="<?php echo $invoice_shipping; ?>">
</div>
</div>
</div>
<?php if (ENABLE_VAT == true) { ?>
<div class="row">
<div class="col-xs-3 col-xs-offset-6">
<strong>TAX/VAT:</strong>
</div>
<div class="col-xs-3">
<?php echo CURRENCY ?><span class="invoice-vat" data-enable-vat="<?php echo ENABLE_VAT ?>" data-vat-rate="<?php echo VAT_RATE ?>" data-vat-method="<?php echo VAT_INCLUDED ?>">0.00</span>
<input type="hidden" name="invoice_vat" id="invoice_vat">
</div>
</div>
<?php } ?>
<div class="row">
<div class="col-xs-3 col-xs-offset-6">
<strong>Total:</strong>
</div>
<div class="col-xs-3">
<?php echo CURRENCY ?><span class="invoice-total"> <?php echo $invoice_total; ?></span>
<input type="hidden" name="invoice_total" id="invoice_total" value="<?php echo $invoice_total; ?>">
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12 margin-top btn-group">
<input type="submit" id="action_edit_invoice" class="btn btn-success float-right" value="Update Invoice" data-loading-text="Updating...">
</div>
</div>
</form>
<div id="insert" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Select an item</h4>
</div>
<div class="modal-body">
<?php popProductsList(); ?>
</div>
<div class="modal-footer">
<button type="button" data-dismiss="modal" class="btn btn-primary" id="selected">Add</button>
<button type="button" data-dismiss="modal" class="btn">Cancel</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<?php
include('footer.php');
?>

Try this out:
SELECT p.*, i.*, c.*
FROM invoice_items p
JOIN invoices i ON i.invoice = p.invoice
JOIN customers c ON c.invoice = i.invoice
WHERE p.invoice = '" . $mysqli->real_escape_string($getID) . "'
Please make sure that:
i.invoice, c.invoice and p.invoice exists and has an index on each table
PS: This query will return multiple entries depending on how many invoice_items are stored for the selected invoice

Try with this query
SELECT *
FROM invoices i,customers c,invoice_items p where
c.invoice = i.invoice and p.invoice = i.invoice and
i.invoice = '".$getID."' ORDER BY i.invoice
if ($mysqli->query("SELECT *
FROM invoices i,customers c,invoice_items p where
c.invoice = i.invoice and p.invoice = i.invoice and
i.invoice = '".$getID."' ORDER BY i.invoice") === TRUE) {
printf("No Error Message.\n");
}

Try run the query directly in database console to see if you can get results. If not, you need check your data.
Also you are using direct input to build your query, which is dangerous. You need somehow convert the getid to make sure it's a number and only a number.

Related

PHP Session Vairables for Checkout/basket system

Im attempting to build an E-commerce website, I'm trying to use sessions to store a product name, price and quantity in a session variable from my product details page to then be used in my basket/checkout page once the user clicks add to basket.
I have some $_SESSION[] but I get the error :
Notice: Undefined index: prod_Name in C:\MAMP\htdocs\product1_details.php on line 25
Notice: Undefined index: prod_Price in C:\MAMP\htdocs\product1_details.php on line 26
I don't know how to add the product name, price and quantity to a session variable so that I can display it in my basket on another page.
you wont see a session.start() as it is in my application_top.php (I was asked to do it this way)
This is my product details page -
<?php
require('includes/application_top.php');
$page_title='Details';
require('includes/site_header.php');
$_GET['prod_ID'];
$product_id = isset($_REQUEST['prod_ID']) ? (int) $_REQUEST['prod_ID'] : 0;
$pound ="£";
?>
<style>
<?php
require('css/prod_details.css');
?>
</style>
<br>
<br>
<br>
<br>
<br>
<?php $product = get_product_details1($freshKickz_conn); ?>
<?php foreach($product as $productdetails) {
?>
<main class="container">
<!-- Left Column / Headphones Image -->
<div class="left-column">
<img data-image="red" class="active" src="<?= htmlspecialchars($productdetails['images']) ?>" style="height: 400px; width: 400px;" alt="">
</div>
<!-- Right Column -->
<div class="right-column">
<!-- Product Description -->
<div class="product-description">
<h1><?= htmlspecialchars($productdetails['prod_Name']) ?></h1>
<p><?= htmlspecialchars($productdetails['prod_Details']) ?></p>
</div>
<!-- Product Pricing -->
<div class="product-price">
<span><?=$pound?><?= htmlspecialchars($productdetails['prod_Price'])?></span>
Add to Basket
</div>
<br>
<div class="quantity">
<span>Quantity</span>
<br>
<input type="number" min="1" max="9" step="1" value="1">
</div>
</div>
</main>
<?php
} ?>
<script src="js/prodJS.js"></script>
<script>
$(document).ready(function () {
$('.color-choose input').on('click', function () {
var headphonesColor = $(this).attr('data-image');
$('.active').removeClass('active');
$('.left-column img[data-image = ' + headphonesColor + ']').addClass('active');
$(this).addClass('active');
});
});
</script>
<?php
require('includes/application_bottom.php');
require('includes/site_footer.php');
?>
And this is my basket page -
<?php
require('includes/application_top.php');
$page_title='Your Basket';
require('includes/site_header.php');
$_SESSION['p_Name'] = $_POST['prod_Name'];
$_SESSION['p_Price'] = $_POST['prod_Price'];
?>
<style>
<?php
require('css/basket.css');
?>
</style>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<div class="row">
<div class="col-75">
<div class="container">
<form action="/action_page.php">
<div class="row">
<div class="col-50">
<h3>Billing Address</h3>
<label for="fname"><i class="fa fa-user"></i> Full Name</label>
<input type="text" id="fname" name="firstname" placeholder="John M. Doe">
<label for="email"><i class="fa fa-envelope"></i> Email</label>
<input type="text" id="email" name="email" placeholder="john#example.com">
<label for="adr"><i class="fa fa-address-card-o"></i> Address</label>
<input type="text" id="adr" name="address" placeholder="542 W. 15th Street">
<label for="city"><i class="fa fa-institution"></i> City</label>
<input type="text" id="city" name="city" placeholder="New York">
<div class="row">
<div class="col-50">
<label for="state">County</label>
<input type="text" id="county" name="county" placeholder="Cheshire">
</div>
<div class="col-50">
<label for="zip">PostCode</label>
<input type="text" id="postcode" name="postcode" placeholder="SK11 6TF">
</div>
</div>
</div>
<div class="col-50">
<h3>Payment</h3>
<label for="fname">Accepted Cards</label>
<div class="icon-container">
<i class="fa fa-cc-visa" style="color:navy;"></i>
<i class="fa fa-cc-amex" style="color:blue;"></i>
<i class="fa fa-cc-mastercard" style="color:red;"></i>
<i class="fa fa-cc-discover" style="color:orange;"></i>
</div>
<label for="cname">Name on Card</label>
<input type="text" id="cname" name="cardname" placeholder="John More Doe">
<label for="ccnum">Credit card number</label>
<input type="text" id="ccnum" name="cardnumber" placeholder="1111-2222-3333-4444">
<label for="expmonth">Exp Month</label>
<input type="text" id="expmonth" name="expmonth" placeholder="September">
<div class="row">
<div class="col-50">
<label for="expyear">Exp Year</label>
<input type="text" id="expyear" name="expyear" placeholder="2018">
</div>
<div class="col-50">
<label for="cvv">CVV</label>
<input type="text" id="cvv" name="cvv" placeholder="352">
</div>
</div>
</div>
</div>
<label>
<input type="checkbox" checked="checked" name="sameadr"> Shipping address same as billing
</label>
<input type="submit" value="Continue to checkout" class="btn">
</form>
</div>
</div>
<div class="col-25">
<div class="container">
<h4>Cart
<span class="price" style="color:black">
<i class="fa fa-shopping-cart"></i>
<b>4</b>
</span>
</h4>
<p><?= $_SESSION['p_Name']?> <span class="price">$15</span></p>
<p>Product 2 <span class="price">$5</span></p>
<p>Product 3 <span class="price">$8</span></p>
<p>Product 4 <span class="price">$2</span></p>
<hr>
<p>Total <span class="price" style="color:black"><b>$30</b></span></p>
</div>
</div>
</div>
<?php
require('includes/application_bottom.php');
require('includes/site_footer.php');
?>
You are getting the error in $_POST. You are not submitting any form with method POST.

Adding an additional field breaks my query

When I add an additional field to my query, it fails. I have checked the spelling 20 or more times....I do not know what is wrong.. Please help!!
Working code BELOW
if(isset($_POST['UPDATE_RAW'])) {
extract($_POST);
$sql=mysqli_query($db,"update nma_raw set NMA_System='$nmasystem',NMA_Ticket_Number='$nmaticketnum',Tkt_Priority='$tktpriority',Created_On_Worklist='$createdonworklist',Create_Date='$createdate',Create_Time='$createtime',Days_Old='$daysold',Interval_Onlist='$intervalonlist',Check_Status='$checkstatus',Ticket_Status='$ticketstatus',Relate_Status='$relatestatus',WFA_TR_Num='$wfatrnum',Recent_WFA_Dispatch_Status='$recentwfadispatchstatus',Last_Owner='$lastowner',Entity_Status='$entitystatus',Entity='$entity',First_Cond_Type='$firstcondtype',Last_Cond_Type='$lastcondtype',State='$st',CLLI='$clli',Check_Active='$checkactive',Check_Jepd='$checkjepd' WHERE ID='$id'");
if($sql) {
echo "<script>alert('Updated SuccessFully');window.location.href='Active_Tkt_Qry_List_Frm_NMA.php';</script>";
}
else {
echo "<script>alert('Some ERRORS');</script>";
}
}
NOT WORKING CODE BELOW!
if(isset($_POST['UPDATE_RAW'])) {
extract($_POST);
$sql = mysqli_query($db,"update nma_raw set NMA_System='$nmasystem',NMA_Ticket_Number='$nmaticketnum',Tkt_Priority='$tktpriority',Created_On_Worklist='$createdonworklist',Create_Date='$createdate',Create_Time='$createtime',Days_Old='$daysold',Interval_Onlist='$intervalonlist',Check_Status='$checkstatus',Ticket_Status='$ticketstatus',Relate_Status='$relatestatus',WFA_TR_Num='$wfatrnum',Recent_WFA_Dispatch_Status='$recentwfadispatchstatus',Last_Owner='$lastowner',Entity_Status='$entitystatus',Entity='$entity',First_Cond_Type='$firstcondtype',Last_Cond_Type='$lastcondtype',State='$st',CLLI='$clli',Check_Active='$checkactive',Check_Jepd='$checkjepd', Resolved_Date='$resolved_date' WHERE ID='$id'");
if($sql) {
echo "<script>alert('Updated SuccessFully');window.location.href='Active_Tkt_Qry_List_Frm_NMA.php';</script>";
}
else {
echo "<script>alert('Some ERRORS');</script>";
}
}
HERE IS A PICTURE OF MY DB SCHEMA
enter image description here
HERE IS THE TOTAL PHP FILE
<?php include_once "header.php";?>
<section class="content">
<div class="page-body clearfix">
<?php
$id=$_REQUEST['id'];
$sql=mysqli_query($db,"SELECT NMA_RAW.*, NMA_RAW.Check_Status, NMA_RAW.Resolved_Date, NMA_RAW.Filtered_Date FROM NMA_RAW WHERE (((NMA_RAW.Check_Status)='OK') AND ((NMA_RAW.Resolved_Date) Is Null) AND ((NMA_RAW.Filtered_Date) Is Null)) AND NMA_RAW.ID = $id;");
$row = mysqli_fetch_array($sql);
?>
<div class="panel panel-default">
<div class="panel-heading">NMA Active Ticket Form</div>
<div class="panel-body">
<form class="form-horizontal" action="" method="post">
<div class="form-group">
<div class="col-sm-4">
<label>NMA System</label>
<input type="text" id="nma_system" class="form-control" placeholder="NMA System" value="<?= $row['NMA_System']; ?>" name="nmasystem">
</div>
<div class="col-sm-4">
<label>NMA Ticket Number</label>
<input type="text" id="nma_ticket_number" class="form-control" placeholder="NMA Ticket Number" value="<?= $row['NMA_Ticket_Number']; ?>" name="nmaticketnum">
</div>
<div class="col-sm-4">
<label>Ticket Priority</label>
<input type="text" id="ticket_priority" class="form-control" placeholder="Ticket Priority" value="<?= $row['Tkt_Priority']; ?>" name="tktpriority">
</div>
</div>
<div class="form-group">
<div class="col-sm-4">
<label>Created On Worklist</label>
<input type="text" id="created_on_work_list" class="form-control" placeholder="Created On Worklist" value="<?= $row['Created_On_Worklist']; ?>" name="createdonworklist">
</div>
<div class="col-sm-4">
<label>Created Date</label>
<div class="input-group">
<span class="input-group-addon">
<i class="fa fa-calendar"></i>
</span>
<input type="date" id="created_date" class="form-control" placeholder="Created Date" value="<?= $row['Create_Date']; ?>" name="createdate">
</div>
</div>
<div class="col-sm-4">
<label>Created time</label>
<div class="input-group">
<span class="input-group-addon">
<i class="fa fa-calendar"></i>
</span>
<input type="time" id="created_time" class="form-control" placeholder="Created Time" value="<?= $row['Create_Time']; ?>" name="createtime">
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-4">
<label>Days Old</label>
<input type="text" id="days_old" class="form-control" placeholder="Days old" value="<?= $row['Days_Old']; ?>" name="daysold">
</div>
<div class="col-sm-4">
<label>Check</label>
<input type="text" id="check" class="form-control" placeholder="Check" value="<?= $row['Check_Status']; ?>" name="checkstatus">
</div>
<div class="col-sm-4">
<label>Ticket Status</label>
<input type="text" id="ticket_status" class="form-control" placeholder="Ticket Status" value="<?= $row['Ticket_Status']; ?>" name="ticketstatus">
</div>
</div>
<div class="form-group">
<div class="col-sm-4">
<label>Interval</label>
<input type="text" id="interval" class="form-control" placeholder="Interval" value="<?= $row['Interval_Onlist']; ?>" name="intervalonlist">
</div>
<div class="col-sm-4">
<label>Related Status</label>
<input type="text" id="relate_status" class="form-control" placeholder="Relate Status" value="<?= $row['Relate_Status']; ?>" name="relatestatus">
</div>
<div class="col-sm-4">
<label>WFA TR Num</label>
<input type="text" id="wfa_tr_num" class="form-control" placeholder="WF TR Num" value="<?= $row['WFA_TR_Num']; ?>" name="wfatrnum">
</div>
</div>
<div class="form-group">
<div class="col-sm-4">
<label>Recent WFA Dispatch Status</label>
<input type="text" id="recent_wfa_dispatch_status" class="form-control" placeholder="Recent WFA Dispatch Status"
value="<?= $row['Recent_WFA_Dispatch_Status']; ?>" name="recentwfadispatchstatus">
</div>
<div class="col-sm-4">
<label>Entity Status</label>
<input type="text" id="entity_status" class="form-control" placeholder="Intity Status" value="<?= $row['Entity_Status']; ?>" name="entitystatus">
</div>
<div class="col-sm-4">
<label>Entity</label>
<input type="text" name="entity" id="entity" class="form-control" placeholder="Entity" value="<?= $row['Entity']; ?>" name="entity">
</div>
</div>
<div class="form-group">
<div class="col-sm-4">
<label>Last Owner</label>
<input type="text" id="last_owner" class="form-control" placeholder="Last Owner" value="<?= $row['Last_Owner']; ?>" name="lastowner">
</div>
<div class="col-sm-4">
<label>First Cond Type</label>
<input type="text" id="first_cond_type" class="form-control" placeholder="First Cond Type" value="<?= $row['First_Cond_Type']; ?>" name="firstcondtype">
</div>
<div class="col-sm-4">
<label>Last Cond Type</label>
<input type="text" id="last_cond_type" class="form-control" placeholder="Last Cond Type" value="<?= $row['Last_Cond_Type']; ?>" name="lastcondtype">
</div>
</div>
<div class="form-group">
<div class="col-sm-4">
<label>State</label>
<input type="text" id="state" class="form-control" placeholder="State" value="<?= $row['State']; ?>" name="st">
</div>
<div class="col-sm-4">
<label>Check Active</label>
<input type="text" id="check_active" class="form-control" placeholder="Check Active" value="<?= $row['Check_Active']; ?>" name="checkactive">
</div>
<div class="col-sm-4">
<label>Check Jepd</label>
<input type="text" name="check_jepd" id="check_jepd" class="form-control"placeholder="Check Jepd" value="<?= $row['Check_Jepd']; ?>" name="checkjepd">
</div>
</div>
<div class="form-group">
<div class="col-sm-4">
<label>CLLI</label>
<input type="text" id="clli" class="form-control" placeholder="CLLI" value="<?= $row['CLLI']; ?>" name="clli">
</div>
<div class="col-sm-4">
<label>Resolved Date</label>
<div class="input-group">
<span class="input-group-addon">
<i class="fa fa-calendar"></i>
</span>
<input type="date" id="resolved_date" class="form-control" placeholder="Resolved_Date" value="<?= $row['Resolved_Date']; ?>" name="resolved_date">
</div>
</div>
<div class="col-sm-4">
<label>Filtered Date</label>
<div class="input-group">
<span class="input-group-addon">
<i class="fa fa-calendar"></i>
</span>
<input type="date" id="filtered_date" class="form-control" placeholder="Filtered Date" value="<?= $row['Filtered_Date']; ?>" name="filtereddate">
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-4">
<label>Filtered By</label>
<input type="text" id="filtered_by" class="form-control" placeholder="Filtered by" value="<?= $row['Filtered_By']; ?>" name="filteredby">
</div>
<div class="col-sm-4">
<label>Restored Date</label>
<div class="input-group">
<span class="input-group-addon">
<i class="fa fa-calendar"></i>
</span>
<input type="date" id="restored_date" class="form-control" placeholder="Restored_Date" value="<?= $row['Restored_Date']; ?>" name="restoreddate">
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-4 ">
<label class="text-bold"> NMA Comments subform </label>
</div>
<div class="col-sm-4">
</div>
</div>
<hr>
<div class="form-group">
<?php
$io = mysqli_query($db,"select * from NMA_Comments where NMA_Tkt_Num='$row[NMA_Ticket_Number]'");
$tr=mysqli_fetch_assoc($io);
?>
<div class="col-sm-4">
<label>NMA Ticket Number</label>
<input type="text" name="NMA_Ticket_Number" id="nma_ticket_number" class="form-control" placeholder="NMA Ticket Number" value="<?php echo $tr['NMA_Tkt_Num']; ?>" >
</div>
<div class="col-sm-4">
<label>NMA Notes</label>
<textarea type="text" name="NMA_Notes" id="nma_notes" class="form-control" placeholder="NMA Notes"><?php echo $tr['NMA_Notes']; ?></textarea>
</div>
<div class="col-sm-4">
<label>NMA Note Date</label>
<input type="text" name="NMA_Ticket_Date" id="nma_ticket_number" class="form-control" placeholder="NMA Ticket Number" value="<?php echo $tr['NMA_Note_Date']; ?>">
</div>
</div>
<div class="form-group">
<div class="col-sm-4">
<button class="btn btn-primary" name="UPDATE_RAW"> Save and Close</button>
</div>
<div class="col-sm-4">
<button class="btn btn-success" name="MOVE_TO_RESOLVED"> Resolved and Close</button>
</div>
<div class="col-sm-4">
<button class="btn btn-danger" name="MOVE_TO_INHIBITS"> Inhibit and Close</button>
</div>
</div>
</form>
</div>
</div>
</div>
</section>
<?php
if(isset($_POST['UPDATE_RAW'])){
extract($_POST);
//print_r($_POST);
$sql=mysqli_query($db,"update nma_raw set NMA_System='$nmasystem',NMA_Ticket_Number='$nmaticketnum',Tkt_Priority='$tktpriority',Created_On_Worklist='$createdonworklist',Create_Date='$createdate',Create_Time='$createtime',Days_Old='$daysold',Interval_Onlist='$intervalonlist',Check_Status='$checkstatus',Ticket_Status='$ticketstatus',Relate_Status='$relatestatus',WFA_TR_Num='$wfatrnum',Recent_WFA_Dispatch_Status='$recentwfadispatchstatus',Last_Owner='$lastowner',Entity_Status='$entitystatus',Entity='$entity',First_Cond_Type='$firstcondtype',Last_Cond_Type='$lastcondtype',State='$st',CLLI='$clli',Check_Active='$checkactive',Check_Jepd='$checkjepd', Resolved_Date='$resolved_date' WHERE ID='$id'");
if($sql){
echo"<script>alert('Updated SuccessFully');window.location.href='Active_Tkt_Qry_List_Frm_NMA.php';</script>";
}
else{
echo"<script>alert('Some ERRORS');</script>";
}
}
?>
<?php
if(isset($_POST['MOVE_TO_INHIBITS'])){
extract($_POST);
//$print_r($_POSt);
$sql=mysqli_query($db,"INSERT INTO nma_main_table SELECT * FROM nma_raw where ID='$id'");
if($sql){
echo"<script>alert('Updated SuccessFully');window.location.href='Active_Tkt_Qry_List_Frm_NMA.php';</script>";
}
else{
echo"<script>alert('Some ERRORS');</script>";
}
// sql to delete a record
$sql=mysqli_query($db,"DELETE FROM nma_raw WHERE ID='$id'");
if ($sql){
echo "Record Inhibited successfully";
} else {
echo "<script>alert('Error in deletion');</script>";
}
}
?>
<?php
if(isset($_POST['MOVE_TO_RESOLVED'])){
extract($_POST);
//$print_r($_POSt);
$sql=mysqli_query($db,"INSERT INTO nma_main_table SELECT * FROM nma_raw where ID='$id'");
if($sql){
echo"<script>alert('Updated SuccessFully');window.location.href='Active_Tkt_Qry_List_Frm_NMA.php';</script>";
}
else{
echo"<script>alert('Some ERRORS');</script>";
}
// sql to delete a record
$sql=mysqli_query($db,"DELETE FROM nma_raw WHERE ID='$id'");
if ($sql){
echo "Record Resolved successfully";
} else {
echo "<script>alert('Error in deletion');</script>";
}
}
?>
<?php include_once "footer.php";?>
If the error you're getting is Incorrect date value: '' for column 15daytkt.nma_raw.Resolved_Date (as you've mentioned in the comments) :
It looks like you are passing an empty string to the Resolved_Date column, and it's invalid. Please make sure you're actually passing a valid date string in this format 2019-11-15. Usually, the HTML form inputs with the date type return this format.
You can verify this case by setting the value to NULL if it's empty. Try changing the query as below:
$sql = mysqli_query($db,"update nma_raw set NMA_System='$nmasystem', Resolved_Date=NULLIF($resolved_date, '') WHERE ID='$id'");
Note the NULLIF($resolved_date, '') part. It will basically set the value to null if it is empty.
Hope it helps.

updating data from php to mysql creating blank data

I have a webpage in php which has some form data in sql the user can update the data.
The form is like below:
<?php
$id=$_GET['id'];
$SelSql = "SELECT * FROM `registers` WHERE id=$id";
$res = mysqli_query($link, $SelSql);
$r = mysqli_fetch_assoc($res);
?>
<?php if(isset($fmsg)){ ?><div class="alert alert-danger" role="alert"> <?php echo $fmsg; ?> </div><?php } ?>
<div class="breadcrumbs">
<div class="breadcrumbs-inner">
<div class="row m-0">
<div class="col-sm-4">
<div class="page-header float-left">
<div class="page-title">
<h1>Member Details</h1>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="content">
<div class="animated fadeIn">
<div class="row">
<div class="col-xs-6 col-sm-6">
<div class="card">
<div class="card-body card-block">
<div class="form-group">
<label class=" form-control-label">Member ID</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-id-card-o"></i></div>
<input class="form-control" value="<?php echo $r['id']; ?>" readonly>
</div>
</div>
<form method="post">
<div class="form-group">
<label class=" form-control-label">First Name</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-address-card-o"></i></div>
<input name="fname" class="form-control" value="<?php echo $r['firstname']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Last Name</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-address-card-o"></i></div>
<input name="lname" class="form-control" value="<?php echo $r['lastname']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Mobile Number</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-mobile"></i></div>
<input name="mobile" class="form-control" value="<?php echo $r['mobilenumber']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Company</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-building"></i></div>
<input name="company" class="form-control" value="<?php echo $r['company']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Designation</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-clipboard"></i></div>
<input name="designation" class="form-control" value="<?php echo $r['designation']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Experience</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-sort-numeric-asc"></i></div>
<input name="experience" class="form-control" value="<?php echo $r['experience']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Address</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-map-marker"></i></div>
<input name="address" class="form-control" value="<?php echo $r['address']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Address Line 2</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-map-marker"></i></div>
<input name="addressline2" class="form-control" value="<?php echo $r['addressline2']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">City</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-building-o"></i></div>
<input name="city" class="form-control" value="<?php echo $r['city']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">State</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-map"></i></div>
<input name="state" class="form-control" value="<?php echo $r['state']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Pin</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-map-pin"></i></div>
<input name="pin" class="form-control" value="<?php echo $r['pin']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Country</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-globe"></i></div>
<input name="country" class="form-control" value="<?php echo $r['country']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Whatsapp Number</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-phone-square"></i></div>
<input name="whatsapp" class="form-control" value="<?php echo $r['Whatsapp']; ?>">
</div>
</div>
</div>
</div>
</div>
<div class="col-xs-6 col-sm-6">
<div class="card">
<div class="card-body card-block">
<div class="form-group">
<label class=" form-control-label">Alternate Number</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-phone"></i></div>
<input name="alternate" class="form-control" value="<?php echo $r['alternatenumber']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Email</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-envelope"></i></div>
<input name="email" class="form-control" value="<?php echo $r['Email']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Company Registration Number</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-registered"></i></div>
<input name="crn" class="form-control" value="<?php echo $r['CompanyRegNumber']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Date of Incorporation</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-calendar"></i></div>
<input name="doi" class="form-control" value="<?php echo $r['Date_Incorporation_orBusi_Stp']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">GST IN</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-sort-numeric-asc"></i></div>
<input name="gstin" class="form-control" value="<?php echo $r['GSTIN']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Services Offered</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-question-circle"></i></div>
<input name="services" class="form-control" value="<?php echo $r['Services_Offered']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Annual Turnover</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-money"></i></div>
<input name="annualt" class="form-control" value="<?php echo $r['Annual_Turnover']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Fee</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-money"></i></div>
<input name="fee" class="form-control" value="<?php echo $r['Fee']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Mode of Payment</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-credit-card"></i></div>
<input name="mop" class="form-control" value="<?php echo $r['Mode_of_Payment']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Recommended By (A)</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-user"></i></div>
<input name="reca" class="form-control" value="<?php echo $r['Recommended_by_A']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Recommended By (B)</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-user"></i></div>
<input name="recb" class="form-control" value="<?php echo $r['Recommended_by_B']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Terms and Conditions</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-check"></i></div>
<input name="tac" class="form-control" value="<?php echo $r['termsandconditions']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Declaration</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-check"></i></div>
<input name="dec" class="form-control" value="<?php echo $r['Declaration']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Confirmation</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-check"></i></div>
<input name="cof" class="form-control" value="<?php echo $r['confirmation']; ?>">
</div>
</div>
<input type="submit" class="btn btn-primary" value="Update">
</form>
</div>
</div>
</div>
<?php
if(isset($_POST) & !empty($_POST)){
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['mobile'];
$company = $_POST['company'];
$designation = $_POST['designation'];
$experience = $_POST['experience'];
$address = $_POST['address'];
$addressline2 = $_POST['addressline2'];
$city = $_POST['city'];
$state = $_POST['state'];
$pin = $_POST['pin'];
$country = $_POST['country'];
$whatsapp = $_POST['whatsapp'];
$alternate = $_POST['alternate'];
$email = $_POST['email'];
$crn = $_POST['crn'];
$doi = $_POST['doi'];
$gstin = $_POST['gstin'];
$services = $_POST['services'];
$annualt = $_POST['annualt'];
$fee = $_POST['fee'];
$mop = $_POST['mop'];
$reca = $_POST['reca'];
$recb = $_POST['recb'];
$tac = $_POST['tac'];
$dec = $_POST['dec'];
$cof = $_POST['cof'];
}
$UpdateSql = "UPDATE `registers` SET firstname='$fname', lastname='$lname', mobilenumber='$email', experience='$experience',
designation='$designation', company='$company', address='$address', addressline2='$addressline2',
city='$city', state='$state', pin='$pin', country='$country',
Whatsapp='$whatsapp', alternatenumber='$alternate', Email='$email', CompanyRegNumber='$crn',
Date_Incorporation_orBusi_Stp='$doi', GSTIN='$gstin', Services_Offered='$services', Annual_Turnover='$annualt',
Declaration='$dec', Fee='$fee', confirmation='$cof', Mode_of_Payment='$mop',
Recommended_by_A='$reca', Recommended_by_B='$recb', termsandconditions='$tac' WHERE id=$id";
$res = mysqli_query($link, $UpdateSql);
if($res){
header('location: update.php');
}else{
$fmsg = "Failed to update data.";
}
?>
the update feature is working completely fine, when the user loads this page, the data is displayed in the form which is editable by user,now the problem is when the user updates the data, the page reloads and updates the data in database but, the page is displayed with empty values in the input fields, such that if the user clicks the update button again by mistake, the database field becomes blank. what is the problem in my code, what should i do to stop this mistake?
The issue is fundamentally how you are passing parameters. If you are POSTing then the parameter id will not be accessible with your current code, which expects id to be a GET parameter. Try this:
$id=$_POST['id'];
Or better yet,
$id=$_REQUEST['id'];
The $_REQUEST variable is an associative array that by default contains the contents of $_GET, $_POST and $_COOKIE. Since it seems that you need the id parameter for both GET and POST methods, $_REQUEST should be used here.
UPDATE
Your mysqli_query($link, $UpdateSql) function should be wrapped in the if(isset($_POST) & !empty($_POST)) condition. It looks like it is executing on each load the way the code currently is.
if(isset($_POST) & !empty($_POST)){
...
$UpdateSql = "....."
$res = mysqli_query($link, $UpdateSql);
}
Pass id, when you are redirecting page, on success as following
if($res){
header('location: update.php?id='.$id);
exit;
}else{
$fmsg = "Failed to update data.";
}

Getting data from MySQLi using set ID not working

Any ideas what I'm doing wrong here? I'm getting the getID back fine as it's displaying when I echo on page but nothing else is getting set from database that I'm requesting.
I have tried a few things but cannot seem to crack it; I think maybe it might be bad markup from my side with the actual select query and how I put in the getID but might be wrong.
I've also added a foreach to list products, that might be wrong as well.
PHP / HTML
include('includes/config.php');
include('header.php');
include('functions.php');
$getID = $_GET['id'];
// Connect to the database
$mysqli = new mysqli(DATABASE_HOST, DATABASE_USER, DATABASE_PASS, DATABASE_NAME);
// output any connection error
if ($mysqli->connect_error) {
die('Error : ('.$mysqli->connect_errno .') '. $mysqli->connect_error);
}
// the query
$query = "SELECT i.*
FROM invoices as i
JOIN customers as c ON c.invoice = ".$getID."
JOIN invoice_items as p ON p.invoice = ".$getID."
ORDER BY i.invoice";
// mysqli select query
$results = $mysqli->query($query);
// mysqli select query
if($results) {
$customer_name = $row['customer_name']; // customer name
$customer_email = $row['customer_email']; // customer email
$customer_address_1 = $row['customer_address_1']; // customer address
$customer_address_2 = $row['customer_address_2']; // customer address
$customer_town = $row['customer_town']; // customer town
$customer_county = $row['customer_county']; // customer county
$customer_postcode = $row['customer_postcode']; // customer postcode
$customer_phone = $row['customer_phone']; // customer phone number
//shipping
$customer_name_ship = $row['customer_name_ship']; // customer name (shipping)
$customer_address_1_ship = $row['customer_address_1_ship']; // customer address (shipping)
$customer_address_2_ship = $row['customer_address_2_ship']; // customer address (shipping)
$customer_town_ship = $row['customer_town_ship']; // customer town (shipping)
$customer_county_ship = $row['customer_county_ship']; // customer county (shipping)
$customer_postcode_ship = $row['customer_postcode_ship']; // customer postcode (shipping)
// invoice details
$invoice_number = $row['invoice_id']; // invoice number
$invoice_date = $row['invoice_date']; // invoice date
$invoice_due_date = $row['invoice_due_date']; // invoice due date
$invoice_subtotal = $row['invoice_subtotal']; // invoice sub-total
$invoice_shipping = $row['invoice_shipping']; // invoice shipping amount
$invoice_discount = $row['invoice_discount']; // invoice discount
$invoice_vat = $row['invoice_vat']; // invoice vat
$invoice_total = $row['invoice_total']; // invoice total
$invoice_notes = $row['invoice_notes']; // Invoice notes
$invoice_status = $row['invoice_status']; // Invoice status
}
?>
<h1>Edit Invoice (<?php echo $getID; ?>)</h1>
<hr>
<div id="response" class="alert alert-success" style="display:none;">
×
<div class="message"></div>
</div>
<form method="post" id="create_invoice">
<input type="hidden" name="action" value="create_invoice">
<div class="row">
<div class="col-xs-5">
<h1>
<img src="<?php echo COMPANY_LOGO ?>" class="img-responsive">
</h1>
</div>
<div class="col-xs-7 text-right">
<div class="row">
<div class="col-xs-9">
<h1>INVOICE</h1>
</div>
<div class="col-xs-3">
<select name="invoice_status" id="invoice_status" class="form-control">
<option value="open" <?php if($invoice_status == "open"){?>selected<?php } ?>>Open</option>
<option value="paid" <?php if($invoice_status == "paid"){?>selected<?php } ?>>Paid</option>
</select>
</div>
</div>
<div class="col-xs-4 no-padding-right">
<div class="form-group">
<div class="input-group date" id="invoice_date">
<input type="text" class="form-control required" name="invoice_date" placeholder="Select invoice date" data-date-format="<?php echo DATE_FORMAT ?>" value="<?php echo $invoice_date; ?>" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
<div class="col-xs-4">
<div class="form-group">
<div class="input-group date" id="invoice_due_date">
<input type="text" class="form-control required" name="invoice_due_date" placeholder="Select due date" data-date-format="<?php echo DATE_FORMAT ?>" value="<?php echo $invoice_due_date; ?>" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
<div class="input-group col-xs-4 float-right">
<span class="input-group-addon">#<?php echo INVOICE_PREFIX ?></span>
<input type="text" name="invoice_id" id="invoice_id" class="form-control required" placeholder="Invoice Number" aria-describedby="sizing-addon1" value="<?php echo $getID; ?>">
</div>
</div>
</div>
<div class="row">
<div class="col-xs-6">
<div class="panel panel-default">
<div class="panel-heading">
<h4>Customer Information</h4>
<div class="clear"></div>
</div>
<div class="panel-body form-group form-group-sm">
<div class="row">
<div class="col-xs-6">
<div class="form-group">
<input type="text" class="form-control margin-bottom copy-input required" name="customer_name" id="customer_name" placeholder="Enter name" tabindex="1" value="<?php echo $customer_name; ?>">
</div>
<div class="form-group">
<input type="text" class="form-control margin-bottom copy-input required" name="customer_address_1" id="customer_address_1" placeholder="Address 1" tabindex="3" value="<?php echo $customer_address_1; ?>">
</div>
<div class="form-group">
<input type="text" class="form-control margin-bottom copy-input required" name="customer_town" id="customer_town" placeholder="Town" tabindex="5" value="<?php echo $customer_town; ?>">
</div>
<div class="form-group no-margin-bottom">
<input type="text" class="form-control copy-input required" name="customer_postcode" id="customer_postcode" placeholder="Postcode" tabindex="7" value="<?php echo $customer_postcode; ?>">
</div>
</div>
<div class="col-xs-6">
<div class="input-group float-right margin-bottom">
<span class="input-group-addon">#</span>
<input type="email" class="form-control copy-input required" name="customer_email" id="customer_email" placeholder="E-mail address" aria-describedby="sizing-addon1" tabindex="2" value="<?php echo $customer_email; ?>">
</div>
<div class="form-group">
<input type="text" class="form-control margin-bottom copy-input" name="customer_address_2" id="customer_address_2" placeholder="Address 2" tabindex="4" value="<?php echo $customer_address_2; ?>">
</div>
<div class="form-group">
<input type="text" class="form-control margin-bottom copy-input required" name="customer_county" id="customer_county" placeholder="County" tabindex="6" value="<?php echo $customer_county; ?>">
</div>
<div class="form-group no-margin-bottom">
<input type="text" class="form-control required" name="customer_phone" id="invoice_phone" placeholder="Phone number" tabindex="8" value="<?php echo $customer_phone; ?>">
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-xs-6 text-right">
<div class="panel panel-default">
<div class="panel-heading">
<h4>Shipping Information</h4>
</div>
<div class="panel-body form-group form-group-sm">
<div class="row">
<div class="col-xs-6">
<div class="form-group">
<input type="text" class="form-control margin-bottom required" name="customer_name_ship" id="customer_name_ship" placeholder="Enter name" tabindex="9" value="<?php echo $customer_name_ship; ?>">
</div>
<div class="form-group">
<input type="text" class="form-control margin-bottom" name="customer_address_2_ship" id="customer_address_2_ship" placeholder="Address 2" tabindex="11" value="<?php echo $customer_address_2_ship; ?>">
</div>
<div class="form-group no-margin-bottom">
<input type="text" class="form-control required" name="customer_county_ship" id="customer_county_ship" placeholder="County" tabindex="13" value="<?php echo $customer_county_ship; ?>">
</div>
</div>
<div class="col-xs-6">
<div class="form-group">
<input type="text" class="form-control margin-bottom required" name="customer_address_1_ship" id="customer_address_1_ship" placeholder="Address 1" tabindex="10" value="<?php echo $customer_address_1_ship; ?>">
</div>
<div class="form-group">
<input type="text" class="form-control margin-bottom required" name="customer_town_ship" id="customer_town_ship" placeholder="Town" tabindex="12" value="<?php echo $customer_town_ship; ?>">
</div>
<div class="form-group no-margin-bottom">
<input type="text" class="form-control required" name="customer_postcode_ship" id="customer_postcode_ship" placeholder="Postcode" tabindex="14" value="<?php echo $customer_postcode_ship; ?>">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- / end client details section -->
<table class="table table-bordered" id="invoice_table">
<thead>
<tr>
<th width="500">
<h4><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Item</h4>
</th>
<th>
<h4>Qty</h4>
</th>
<th>
<h4>Price</h4>
</th>
<th width="300">
<h4>Discount</h4>
</th>
<th>
<h4>Sub Total</h4>
</th>
</tr>
</thead>
<tbody>
<?php
foreach($invoice_product as $key => $value) {
$item_product = $value;
// $item_description = $_POST['invoice_product_desc'][$key];
$item_qty = $row['invoice_product_qty'][$key];
$item_price = $row['invoice_product_price'][$key];
$item_discount = $row['invoice_product_discount'][$key];
$item_subtotal = $row['invoice_product_sub'][$key];
?>
<tr>
<td>
<div class="form-group form-group-sm no-margin-bottom">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
<input type="text" class="form-control form-group-sm item-input invoice_product" name="invoice_product[]" placeholder="Enter item title and / or description" value="<?php echo $item_product; ?>">
<p class="item-select">or select an item</p>
</div>
</td>
<td class="text-right">
<div class="form-group form-group-sm no-margin-bottom">
<input type="text" class="form-control calculate" name="invoice_product_qty[]" value="1" value="<?php echo $item_qty; ?>">
</div>
</td>
<td class="text-right">
<div class="input-group input-group-sm no-margin-bottom">
<span class="input-group-addon"><?php echo CURRENCY ?></span>
<input type="text" class="form-control calculate invoice_product_price required" name="invoice_product_price[]" aria-describedby="sizing-addon1" placeholder="0.00" value="<?php echo $item_price; ?>">
</div>
</td>
<td class="text-right">
<div class="form-group form-group-sm no-margin-bottom">
<input type="text" class="form-control calculate" name="invoice_product_discount[]" placeholder="Enter % or value (ex: 10% or 10.50)" value="<?php echo $item_discount; ?>">
</div>
</td>
<td class="text-right">
<div class="input-group input-group-sm">
<span class="input-group-addon"><?php echo CURRENCY ?></span>
<input type="text" class="form-control calculate-sub" name="invoice_product_sub[]" id="invoice_product_sub" value="0.00" aria-describedby="sizing-addon1" value="<?php echo $item_subtotal; ?>" disabled>
</div>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<div id="invoice_totals" class="padding-right row text-right">
<div class="col-xs-6">
<div class="input-group form-group-sm textarea no-margin-bottom">
<textarea class-"form-control" name="invoice_notes" placeholder="Please enter any order notes here." value="<?php echo $invoice_notes; ?>"></textarea>
</div>
</div>
<div class="col-xs-6 no-padding-right">
<div class="row">
<div class="col-xs-3 col-xs-offset-6">
<strong>Sub Total:</strong>
</div>
<div class="col-xs-3">
<?php echo CURRENCY ?><span class="invoice-sub-total"> <?php echo $invoice_subtotal; ?></span>
<input type="hidden" name="invoice_subtotal" id="invoice_subtotal" value="<?php echo $invoice_subtotal; ?>">
</div>
</div>
<div class="row">
<div class="col-xs-3 col-xs-offset-6">
<strong>Discount:</strong>
</div>
<div class="col-xs-3">
<?php echo CURRENCY ?><span class="invoice-discount"> <?php echo $invoice_discount; ?></span>
<input type="hidden" name="invoice_discount" id="invoice_discount" value="<?php echo $invoice_discount; ?>">
</div>
</div>
<div class="row">
<div class="col-xs-3 col-xs-offset-6">
<strong class="shipping">Shipping:</strong>
</div>
<div class="col-xs-3">
<div class="input-group input-group-sm">
<span class="input-group-addon"><?php echo CURRENCY ?></span>
<input type="text" class="form-control calculate shipping" name="invoice_shipping" aria-describedby="sizing-addon1" placeholder="0.00" value="<?php echo $invoice_shipping; ?>">
</div>
</div>
</div>
<?php if (ENABLE_VAT == true) { ?>
<div class="row">
<div class="col-xs-3 col-xs-offset-6">
<strong>TAX/VAT:</strong>
</div>
<div class="col-xs-3">
<?php echo CURRENCY ?><span class="invoice-vat" data-enable-vat="<?php echo ENABLE_VAT ?>" data-vat-rate="<?php echo VAT_RATE ?>" data-vat-method="<?php echo VAT_INCLUDED ?>">0.00</span>
<input type="hidden" name="invoice_vat" id="invoice_vat">
</div>
</div>
<?php } ?>
<div class="row">
<div class="col-xs-3 col-xs-offset-6">
<strong>Total:</strong>
</div>
<div class="col-xs-3">
<?php echo CURRENCY ?><span class="invoice-total"> <?php echo $invoice_total; ?></span>
<input type="hidden" name="invoice_total" id="invoice_total" value="<?php echo $invoice_total; ?>">
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12 margin-top btn-group">
<input type="submit" id="action_edit_invoice" class="btn btn-success float-right" value="Update Invoice" data-loading-text="Updating...">
</div>
</div>
</form>
<div id="insert" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Select an item</h4>
</div>
<div class="modal-body">
<?php popProductsList(); ?>
</div>
<div class="modal-footer">
<button type="button" data-dismiss="modal" class="btn btn-primary" id="selected">Add</button>
<button type="button" data-dismiss="modal" class="btn">Cancel</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<?php
include('footer.php');
?>
The JOINs in your query are a little strange with constants in your ON clauses
...
JOIN customers as c ON c.invoice = ".$getID."
JOIN invoice_items as p ON p.invoice = ".$getID."
...
You want this instead. Your ON clauses need to express a relationship between rows in your three tables. Putting constant values in those clauses defeats that. Instead use a WHERE clause to filter the correct invoice number.
SELECT something, something
FROM invoices as i
JOIN customers as c ON c.invoice = i.invoice
JOIN invoice_items as p ON p.invoice = i.invoice
WHERE i.invoice = ".$getID."
ORDER BY i.invoice
Secondly, are you sure you have a column called invoice in all three of these tables? Your code mentions a column called invoice_id later on. Is that, in fact, the name of your join column?
Thirdly, it looks like your php code expects columns from two of your three tables to appear in your result set. For example.
....
$customer_postcode_ship = $row['customer_postcode_ship'];
....
$invoice_number = $row['invoice_id'];
...
But you did SELECT c.* which only returns the columns from your customers table.
Pro tip: Avoid * in SELECT clauses. Instead, list out the columns you want. Do something like this:
SELECT customer_name, customer_email, customer_address_1, customer_address_2,
customer_town, customer_county, customer_postcode,
customer_phone, customer_name_ship, customer_address_1_ship,
customer_address_2_ship, customer_town_ship, customer_county_ship,
customer_postcode_ship,
invoice_id, invoice_date, invoice_due_date, invoice_subtotal,
invoice_shipping, invoice_discount, invoice_vat, invoice_total,
invoice_notes, invoice_status
FROM ...
I know this seems impossibly verbose. But it's worth the effort because it allows your php code to be resilient to changes in table structure. It also makes it clear to the programmer who debugs this which columns are available in the result set.
Fourthly, keep in mind that you will get a combinatorial explosion of rows here. You're filtering for just one invoice which is fine. Presumably each invoice relates to only one customer. That too is fine. But, your customer and invoice column values will be repeated once for each matching row from your invoice_items table.
Fifth: check for an error return from $mysqli->query($query);.
$results = $mysqli->query($query);
if (!$results) {
printf("Errormessage: %s\n", $mysqli->error);
} else {
/* process the resultset */
}
As you work with SQL, this stuff will eventually become second nature. Don't get overly annoyed at the complexity of doing it right!

make bootstrap alert disappear automatically

i have a form whch sends data to the databse, after data is sent successfully i want to show success msg, but i dont want it to stay rather to disappear after a short while.
$nameErr=$drug_idErr=$priceErr=$quantityErr=$dateErr=$dateInvalid="";
$drug_id=$name=$price=$quantity=$date="";
if(isset($_POST['submit'])){
$drug_id=mysql_real_escape_string(addslashes($_POST['drug_id']));
$name=mysql_real_escape_string(addslashes($_POST['name']));
$price=mysql_real_escape_string(addslashes($_POST['price']));
$quantity=mysql_real_escape_string(addslashes($_POST['quantity']));
$date=mysql_real_escape_string(addslashes($_POST['date']));
if(empty($drug_id)){
$drug_idErr="Required";
}
elseif(empty($name)){
$nameErr="Required";
}
elseif(empty($price)){
$priceErr="Required";
}
elseif(empty($quantity)){
$quantityErr="Required";
}
elseif(empty($date)){
$dateErr="Required";
}
elseif(!preg_match('/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/', $date)){
$dateInvalid="Invalid date format";
}
else{
//send data to database here
$_SESSION['success']="Drug added successfully";
$drug_id=$name=$price=$quantity=$date="";
}
}
the following is my form
<div class="well">
<form id="register-form" class="form-horizontal" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<legend>Add new drug</legend>
<?php if(!empty($_SESSION['success'])){
echo '<div class="alert alert-success">'.$_SESSION['success'].'</div>'; unset($_SESSION['success']);} ?>
<div class="control-group">
<label class="control-label">ID</label>
<div class="controls">
<div class="input-prepend">
<span class="add-on"><i class="icon-ban-circle"></i></span>
<input type="text" class="input-xlarge" id="drug_id" name="drug_id" placeholder="Drug ID"
value="<?php echo htmlspecialchars($drug_id); ?>">
</div>
<span class="error"><?php echo $drug_idErr;?></span>
</div>
</div>
<div class="control-group ">
<label class="control-label">Name</label>
<div class="controls">
<div class="input-prepend">
<span class="add-on"><i class="icon-pills"></i></span>
<input type="text" class="input-xlarge" id="name" name="name" placeholder="Drug Name"
value="<?php echo htmlspecialchars($name)?>">
</div>
<span class="error"><?php echo $nameErr;?></span>
</div>
</div>
<div class="control-group">
<label class="control-label">Price</label>
<div class="controls">
<div class="input-prepend">
<span class="add-on"><i class="icon-dollars"></i></span>
<input type="text" class="input-small" id="price" name="price" placeholder="Drug Price"
value="<?php echo htmlspecialchars($price); ?>">
</div>
<span class="error"><?php echo $priceErr; ?></span>
</div>
</div>
<div class="control-group">
<label class="control-label">Quantity</label>
<div class="controls">
<div class="input-prepend">
<span class="add-on"><i class="icon-ban-circle"></i></span>
<input type="text" id="quantity" class="input-mini" name="quantity" placeholder="Quantity"
value="<?php echo htmlspecialchars($quantity);?>">
</div>
<span class="error"><?php echo $quantityErr;?></span>
</div>
</div>
<div class="control-group">
<label class="control-label">Expire Date</label>
<div class="controls">
<div class="input-prepend">
<span class="add-on"><i class="icon-time"></i></span>
<td><input type="text" name="date" id="date" class="span2" placeholder="Expire date"
value="<?php echo htmlspecialchars($date); ?>"/>
</div>
<span class="error"><?php echo $dateErr.$dateInvalid; ?></span>
</div>
</div>
<div class="control-group">
<label class="control-label"></label>
<div class="controls">
<button type="submit" class="btn btn-success" name="submit" >Add</button>
</div>
</div>
</form>
</div>
now i can just show the alert but i don knw how to make it disappear
Try this:
$('.alert').hide()
Or you could use fading:
$('.alert').fadeOut(300)

Categories