-
Notifications
You must be signed in to change notification settings - Fork 0
/
single-recipe-ingredient.php
92 lines (79 loc) · 3.84 KB
/
single-recipe-ingredient.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php require_once('components/header.php'); ?>
<?php
/**
* Single page
* Pantry item
* Only for editing a pantry item
*/
$nRecipeId = $_GET['recipeid'];
$nFoodItemId = $_GET['fooditemid'];
$host = 'localhost';
$user = 'root';
$pass = '';
$db = 'myvirtualpantry';
$dsn = "mysql:host=$host;dbname=$db";
$options = [
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
];
$pdo = new PDO($dsn, $user, $pass, $options);
$sqlQuery = "SELECT * FROM trecipeingredient WHERE nRecipeId = :nRecipeId AND nFoodItemId = :nFoodItemId";
$stmt = $pdo->prepare($sqlQuery);
$stmt->execute([
'nRecipeId' => $nRecipeId,
'nFoodItemId' => $nFoodItemId,
]);
$recipeitem = $stmt->fetchObject();
// echo json_encode($recipeitem);
?>
<div class="recipeitem">
<form action="" method="POST" id="frmUpdateRecipeItem">
<div class="input-pair">
<input id="nOldRecipeItemRecipeId" name="nOldRecipeItemRecipeId" type="hidden" value="<?=$recipeitem->nRecipeId?>">
<label for="nNewRecipeItemRecipeId">Recipe</label>
<select id="nNewRecipeItemRecipeId" name="nNewRecipeItemRecipeId" type="text">
<?php
$sqlQuery = "SELECT nRecipeId, cTitle FROM trecipe";
$stmt = $pdo->prepare($sqlQuery);
$stmt->execute();
$rows = $stmt->fetchAll();
foreach($rows as $row) { ?>
<option value="<?=$row->nRecipeId;?>" <?php if($row->nRecipeId == $recipeitem->nRecipeId){echo 'selected';} ?>><?=$row->cTitle;?></option>
<?php } ?>
</select>
</div>
<div class="input-pair">
<input id="nOldRecipeItemFoodItemId" name="nOldRecipeItemFoodItemId" type="hidden" value="<?=$recipeitem->nFoodItemId?>">
<label for="nNewRecipeItemFoodItemId">FoodItem</label>
<select id="nNewRecipeItemFoodItemId" name="nNewRecipeItemFoodItemId" type="text">
<?php
$sqlQuery = "SELECT nFoodItemId, cName FROM tfooditem";
$stmt = $pdo->prepare($sqlQuery);
$stmt->execute();
$rows = $stmt->fetchAll();
foreach($rows as $row) { ?>
<option value="<?=$row->nFoodItemId;?>" <?php if($row->nFoodItemId == $recipeitem->nFoodItemId){echo 'selected';} ?>><?=$row->cName;?></option>
<?php } ?>
</select>
</div>
<div class="input-pair">
<label for="nNewRecipeItemAmount">Amount</label>
<input id="nNewRecipeItemAmount" name="nNewRecipeItemAmount" type="text" value="<?=$recipeitem->nAmount;?>">
</div>
<div class="input-pair">
<label for="nNewRecipeItemMeassurementId">Meassurement</label>
<select id="nNewRecipeItemMeassurementId" name="nNewRecipeItemMeassurementId" type="text">
<?php
$sqlQuery = "SELECT nMeassurementId, cName FROM tmeassurement";
$stmt = $pdo->prepare($sqlQuery);
$stmt->execute();
$rows = $stmt->fetchAll();
foreach($rows as $row) { ?>
<option value="<?=$row->nMeassurementId;?>" <?php if($row->nMeassurementId == $recipeitem->nMeassurementId){echo 'selected';} ?>><?=$row->cName;?></option>
<?php } ?>
</select>
</div>
<div id="btnUpdateRecipeItem" type="submit" name="btnUpdateRecipeItem" onclick="updateRecipeItem(this)">Update recipe ingredient</div>
</form>
</div>
<?php require_once('components/footer.php'); ?>