-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinsertstock.php
37 lines (31 loc) · 1.1 KB
/
insertstock.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
// Establish a connection to your MySQL database
$servername = "your_server_name";
$username = "your_username";
$password = "your_password";
$dbname = "your_database_name";
$conn = new mysqli($servername, $username, $password, $dbname);
// Check the connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Retrieve data from the HTML form
$productName = $_POST['productName'];
$stockQty = $_POST['stockQty'];
$salesPrice = $_POST['salesPrice'];
$costPrice = $_POST['costPrice'];
$datetime = $_POST['datetime'];
$staffName = $_POST['staffName'];
$contact = $_POST['contact'];
$category = $_POST['category'];
// Insert data into the database
$sql = "INSERT INTO product_stock (product_name, stock_qty, sales_price, cost_price, datetime, staff_name, contact, category)
VALUES ('$productName', $stockQty, $salesPrice, $costPrice, '$datetime', '$staffName', '$contact', '$category')";
if ($conn->query($sql) === TRUE) {
echo "Record added successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
// Close the database connection
$conn->close();
?>