I am making a simple Point of Sale system for personal use and I have two table namely: sales and items. Items to be sold are based on the list of items in the items table. Below is the insert code to the sales table. -
if(isset($_POST['sales']))
-
{
-
$id = $_SESSION['posid'];
-
-
$sql = " INSERT
-
INTO sales (uid, itemname, category, price, quantity, amount, paid, changeP, cashier, salesDate)
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
-
-
if($stmt = mysqli_prepare($con, $sql))
-
{
-
mysqli_stmt_bind_param($stmt, "isssssssss", $id, $itemname, $category, $price, $quantity, $amount, $paid, $changeP, $cashier, $salesDate);
-
-
$itemname = mysqli_real_escape_string($con, $_POST['itemname']);
-
$category = mysqli_real_escape_string($con, $_POST['category']);
-
$price = mysqli_real_escape_string($con, $_POST['price']);
-
$quantity = mysqli_real_escape_string($con, $_POST['quantity']);
-
$amount = mysqli_real_escape_string($con, $_POST['amount']);
-
$paid = mysqli_real_escape_string($con, $_POST['paid']);
-
$changeP = mysqli_real_escape_string($con, $_POST['changeP']);
-
$cashier = mysqli_real_escape_string($con, $_POST['cashier']);
-
$salesDate = mysqli_real_escape_string($con, $_POST['salesDate']);
-
-
if(mysqli_stmt_execute($stmt))
-
{
-
echo "<script type='text/javascript'>alert('Payment was successfully processed.');
-
</script>";
-
echo "<script>window.location.href='pos.php'</script>";
-
}
-
else
-
{
-
echo "<script type='text/javascript'>alert('Oops! Something went wrong. Please try again.');
-
</script>";
-
echo "<script>window.location.href='pos.php'</script>";
-
}
-
-
}
-
-
mysqli_stmt_close($stmt); // Close statement
-
-
mysqli_close($con); // Close connection
-
}
-
Now, I want as I insert a purchased item in the sales table, the quantity in the items table to reduce by the number of items being purchased.
I really don't know how to go round this, please help.
1 2738
After writing to the sales table, You need to store quantity of items to be reduced as a php variable, and then make a separate SQL call to the items table using UPDATE: -
UPDATE sales
-
SET columnname = foo;
-
$quantity = foo;
-
UPDATE items
-
SET columnname = $quantity;
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Caroline |
last post by:
I need to update a table by copying a column from another table
(having the same
structure, but on another database), from the record having the same
primary key.
1 - What is the correct...
|
by: terence.parker |
last post by:
I am often faced with the dilemma of whether to use a JOIN query across
three tables in order to grab a bunch of results - or whether to create
another table to represent what I want. The latter is...
|
by: Daniel |
last post by:
I use an Access database to basically take data exports, import them,
manipulate the data, and then turn them into exportable reports. I do
this using numerous macros, and queries to get the data...
|
by: Sami |
last post by:
Please bear with me, and if you answer this question, please do it
step by step. I am new at Access, not at all sophisticated. I am
using Office XP. This will need to be read in Access for...
|
by: Colm O'Hagan |
last post by:
Hi there,
I having a problem with a database I'm setting up, I would be
delighted if someone out there could help.
The database I'm setting up is a task register datebase, it will be
used to...
|
by: Sven Pran |
last post by:
Probably the answer is there just in front of me only awaiting me to
discover it,
but:
1: I want to build a query that returns all records in one table for which
there is no successful "join"...
|
by: Shannan Casteel via AccessMonster.com |
last post by:
I have a table called tblParttest. It has fields PartNo, PartNo2, PartNo3, ..
.., PartNo25 and Quantity, Quantity2, Quantity3, ...Quantity25.
If I enter "1234" into the PartNo field and "4" into...
|
by: rcamarda |
last post by:
I wish to build a table based on values from another table.
I need to populate a table between two dates from another table. Using
the START_DT and END_DT, create records between those dates.
I...
|
by: Rex |
last post by:
Hi,
I want to change a value in one table depending on the value(s) in
another table. I am trying to achieve this in a form.
to elaborate
I have a many-to-many relationship between tables...
|
by: satishkhachane |
last post by:
--------------------------------------------------------------------------------
I want to select one or more columns from one typed datatable and add it to another table . how I can do this ?
...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |