Esempio n. 1
0
<?php

/* 
   Purpose: Demo6 - CRUD Operations
   Author: LV
   Date: October 2015
   
   Uses: d6Sql.php
*/
require_once "recipesql.php";
// if $_POST has a filmpk element, call the update method
if (isset($_POST['recipeid'])) {
    updateRecipe($_POST['recipename'], $_POST['dateadded'], $_POST['instructions'], (int) $_POST['categoryid'], (int) $_POST['cooktime'], $_POST['timeofday'], $_POST['timeofyear'], $_POST['userid'], $_POST['allergieid']);
} else {
    addRecipe($_POST['recipename'], $_POST['dateadded'], $_POST['instructions'], (int) $_POST['categoryid'], (int) $_POST['cooktime'], $_POST['timeofday'], $_POST['timeofyear'], $_POST['userid'], $_POST['allergieid']);
}
header("Location: ../home/home.php");
exit;
<?php

addRecipe();
function addRecipe()
{
    if (isset($_POST['namn_ratt']) and isset($_POST['namn_ratt']) and isset($_POST['namn_ratt']) and isset($_POST['namn_ratt']) and isset($_POST['namn_ratt']) and isset($_POST['namn_ratt']) and isset($_POST['procedure']) and isset($_POST['description'])) {
        echo "Rätt:" . $_POST['namn_ratt'];
        echo "<br/>";
        echo "Kategori:" . $_POST['category'];
        echo "<br/>";
        echo "Tillagningstid:" . $_POST['Tillagningstid'];
        echo "<br/>";
        echo "Serveringsmangd_antal:" . $_POST['Serveringsmangd_antal'];
        echo "<br/>";
        echo "Serveringsmangd_enhet:" . $_POST['Serveringsmangd_enhet'];
        echo "<br/>";
        echo "Svarighet:" . $_POST['Svarighet'];
        echo "<br/>";
        $query = insertNewFoodQuery($_POST['namn_ratt'], $_POST['category'], $_POST['Svarighet'], $_POST['Tillagningstid'], $_POST['description'], $_POST['procedure']);
        $id = executeInsertQuery($query);
        /*echo "Ingrediens:" . $_POST['Ingrediens'][0];
        		echo "<br/>";
        		echo "Ingrediens:" . $_POST['Ingrediens'][1];
        		echo "<br/>";*/
        //echo "Antal Ingredienser: " . sizeof($_POST['Ingrediens']);
        //echo "Ingredient: " . $_POST['Ingrediens'][0][0] ."<br/>";
        if (isset($_POST['Ingrediens'])) {
            $c = count($_POST['Ingrediens']);
            for ($i = 0; $i < $c; $i++) {
                if (!empty($_POST['Ingrediens'][0][$i])) {
                    if ($id > 0) {