Added a class to retrieve the basic item information data.
This commit is contained in:
@@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
include("db/category.php");
|
||||||
|
|
||||||
|
if($_GET["category_name"] != "")
|
||||||
|
{
|
||||||
|
create_category($_GET["category_name"]);
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Create New Category</title>
|
||||||
|
</head>
|
||||||
|
<body >
|
||||||
|
<form action="create_category.php">
|
||||||
|
<label for="category_name">Category Name:</label><input type="text" id="category_name" name="category_name"><br>
|
||||||
|
<button type="submit">Submit</button>
|
||||||
|
</form>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
:root {
|
||||||
|
--main-bg-color: #D3D3D3;
|
||||||
|
--main-font-color: #006400;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
background-color: var(--main-bg-color);
|
||||||
|
color: var(--main-font-color);
|
||||||
|
}
|
||||||
+19
-2
@@ -1,8 +1,25 @@
|
|||||||
<?php
|
<?php
|
||||||
|
require "db.php";
|
||||||
|
|
||||||
function get_category_items($db)
|
function get_category_items()
|
||||||
{
|
{
|
||||||
return mysqli_query($db, "SELECT * FROM `category`");
|
global $conn;
|
||||||
|
$items = mysqli_query($conn, "SELECT * FROM `category`");
|
||||||
|
$conn->close();
|
||||||
|
|
||||||
|
return $items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function create_category($name)
|
||||||
|
{
|
||||||
|
global $conn;
|
||||||
|
$statement = $conn->prepare("INSERT INTO `category` (category_name) VALUES (?)");
|
||||||
|
$statement->bind_param("s", $name);
|
||||||
|
if($statement->execute() == true){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$statement->close();
|
||||||
|
$conn->close();
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
@@ -4,6 +4,6 @@
|
|||||||
$password = '1a9t7y';
|
$password = '1a9t7y';
|
||||||
$db_name = 'inventory';
|
$db_name = 'inventory';
|
||||||
|
|
||||||
$db = mysqli_connect($host, $user_name, $password, $db_name) or die("Failed to
|
$conn = mysqli_connect($host, $user_name, $password, $db_name) or die("Failed to
|
||||||
connect to MySQL: " . mysqli_error($db));
|
connect to MySQL: " . mysqli_error($conn));
|
||||||
?>
|
?>
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
require "db.php";
|
||||||
|
|
||||||
|
function get_item_base_attributes(){
|
||||||
|
global $conn;
|
||||||
|
$query = "SELECT COLUMN_NAME
|
||||||
|
FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE TABLE_SCHEMA = 'inventory' AND TABLE_NAME = 'item_info';";
|
||||||
|
$data = mysqli_query($conn, $query);
|
||||||
|
$conn->close();
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
?>
|
||||||
@@ -1,29 +1,17 @@
|
|||||||
<?php
|
<?php
|
||||||
include_once "db/db.php";
|
//Use require for all DB interaction code
|
||||||
include_once "db/category.php";
|
//https://stackoverflow.com/questions/2418473/difference-between-require-include-require-once-and-include-once
|
||||||
|
require "db/item_info.php";
|
||||||
|
|
||||||
$categories = get_category_items($db);
|
$categories = get_item_base_attributes();
|
||||||
|
foreach($categories as $cat){
|
||||||
if($categories){
|
echo $cat["COLUMN_NAME"];
|
||||||
if($categories->num_rows == 0){
|
|
||||||
header("Location: create_category.php");
|
|
||||||
exit(); //It's good practice to call exit() after a redirect so nothing else gets executed.
|
|
||||||
}
|
|
||||||
while($row = mysqli_fetch_array($categories))
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else{
|
|
||||||
echo "Error";
|
|
||||||
}
|
|
||||||
|
|
||||||
$db->close();
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
|
<link rel="stylesheet" type="text/css" href="css/main.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"folders": [
|
||||||
|
{
|
||||||
|
"path": "."
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"settings": {}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user