Esempio n. 1
0
//Checking session name for security.
include "LoginSecurity.php";
include "db.php";
echo "<h2>Add an item</h2>";
echo "<form action='Food_inventory.php?page=1' method='post'>\n\t\t\t\t\t\t<input type='submit' value='Home' />\n\t\t\t\t\t</form>\n\t\t\t\t";
echo "<hr />";
$action = NULL;
if (isset($_GET['action'])) {
    $action = $_GET['action'];
}
//If they've pressed the Add button.
if (isset($_POST['add'])) {
    add_info();
}
//Displaying the form.
display_food();
//Validate input.
validate();
function display_food()
{
    $categorysql = "SELECT DISTINCT category_description, category_id FROM category ORDER BY category_description";
    $categoryresult = mysql_query($categorysql);
    echo "<form action='?action=submit' method='post' id='add_food_form'>\n\t\t\t\t\t\t<table border=1 class='full_input'>\n\t\t\t\t\t\t\t  <th>Name</th>\n\t\t\t\t\t\t\t  <th>Description</th>\n\t\t\t\t\t\t\t  <th>Price</th>\n\t\t\t\t\t\t\t  <th>Cyclone Card Item</th>\n\t\t\t\t\t\t\t  <th colspan=2>Cyclone Card Price</th>\n\t\t\t\t\t\t<tr>";
    echo "<td><input type='text' name='food_name'</td>";
    echo "<td><textarea name='food_description'></textarea></td>";
    echo "<td><input type='text' name='regular_price'</td>";
    echo "<td><input type='text' placeholder='Yes/No' name='cyclone_card'/></td>\n\t\t\t\t\t\t\t\t<td colspan=2><input type='text' name='cyclone_price' placeholder='Amount or N/A'/></td>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<th>Sale Price</th>\n\t\t\t\t\t\t\t<th colspan=2>Sale Start Date</th>\n\t\t\t\t\t\t\t<th colspan=2>Sale End Date</th>\n\t\t\t\t\t\t\t<th>Category</th>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td><input type='text' name='sale_price' id='sale_price' /></td>\n\t\t\t\t\t\t\t<td colspan=2><input type='text' id='sale_start_date' name='sale_start_date' placeholder='Click to set date..' /></td>\n\t\t\t\t\t\t\t<td colspan=2><input type='text' id='sale_end_date' name='sale_end_date' placeholder='Click to set date..' /></td>\n\t\t\t\t\t\t\t<td><select name='category_id'>\n\t\t\t\t\t\t\t\t\t<option value='' selected disabled>--</option>;\n\t\t\t\t\t\t\t";
    //This is the section to display all food categories (distinct) and default the selection to what the current category is for the food.
    while ($categoryrow = mysql_fetch_array($categoryresult)) {
        echo "<option value='" . $categoryrow['category_id'] . "'>" . $categoryrow['category_description'] . "</option>";
    }
Esempio n. 2
0
include "db.php";
echo "<h2>Edit item</h2>";
echo "<form action='food_inventory.php?page=1' method='POST'>\n\t\t\t\t\t\t<input type='submit' value='Home' />\n\t\t\t\t\t</form>\n\t\t\t\t\t<hr />\n\t\t\t\t";
$id = NULL;
$action = NULL;
if (isset($_GET['action'])) {
    $action = $_GET['id'];
}
if (isset($_GET['id'])) {
    $id = $_GET['id'];
}
if (isset($_POST['update'])) {
    update_info($id);
}
//Display Food.
display_food($id);
//Validate input.
validate();
function display_food($id)
{
    $sql = "SELECT f.food_id, f.food_name, f.food_description, f.regular_price, f.sale_price, f.on_sale,\n\t\t\t\t\t\t\tf.sale_start_date, f.sale_end_date, f.category_id, pic, f.cyclone_card_item, f.cyclone_card_price, c.category_id, c.category_description\n\t\t\t\t\t\t\tFROM food f INNER JOIN category c ON c.category_id = f.category_id\n\t\t\t\t\t\t\tWHERE food_id = " . $id;
    $result = mysql_query($sql);
    //Query to get all unique category types to populate our drop-down list.
    $categorysql = "SELECT DISTINCT category_description, category_id FROM category ORDER BY category_description";
    $categoryresult = mysql_query($categorysql);
    echo "<form action='?action=submit&id=" . $id . "' method='post' id='edit_food_form'>\n\t\t\t\t\t\t<table border=1 class='full_input'>\n\t\t\t\t\t\t<th>Image</th>\n\t\t\t\t\t\t<th>Name</th>\n\t\t\t\t\t\t<th>Description</th>\n\t\t\t\t\t\t<th>Price</th>\n\t\t\t\t\t\t<th>Cyclone Card Item</th>\n\t\t\t\t\t\t<th>Cyclone Card Price</th>\n\t\t\t\t\t";
    while ($row = mysql_fetch_array($result)) {
        //For thumbnails with the food image.
        $im = null;
        $image = $row['pic'];
        if (isset($image) && $image != '') {