function addTagsToDB($conn, $lastId) { //tags $tags = [0 => "american", 1 => "gluten-free", 2 => "beef", 3 => "appetizer", 4 => "asian", 5 => "paleo", 6 => "chicken", 7 => "beverages", 8 => "greek", 9 => "vegan", 10 => "pork", 11 => "breakfast/brunch", 12 => "italian", 13 => "vegetarian", 14 => "poultry", 15 => "dessert", 16 => "jamaican", 17 => "seafood", 18 => "lunch", 19 => "latin", 20 => "salad", 21 => "desi", 22 => "soup"]; //for each tag, check if selected for ($x = 0; $x < count($tags); $x++) { if (isset($_POST[$tags[$x]])) { $tagName = $tags[$x]; $sql = "INSERT INTO Tag (name, type, type_id) \n VALUES ( '{$tagName}', 'RECIPE', '{$lastId}')"; if (!($conn->query($sql) === TRUE)) { cleanDbTables($lastId, $conn); return false; } } } return true; }
$privacyx = getPriv($conn, $recipeId); $friendList = getAllFriends($conn, $recipeId); //echo "FRIEND NAME: $friendList<br>"; closeDBConnection($conn); ?> <?php //if form submitted if ($_SERVER['REQUEST_METHOD'] == "POST") { //connect to db $conn = connectToDb($servername, $username, $password, $dbname); //clean db of old recipe cleanDbTables($recipeId, $conn); $userId = getAuthorId($conn, $_SESSION["username"]); //if friend does not have account if (!checkPrivacy($conn)) { exit("Sorry, your friend(s) is not a registered user."); } $oldRecipeId = $recipeId; $recipeName = getRecipeName($conn); $allSteps = getAllSteps($conn); $privacy = getPrivacy(); updateRecipe($conn, $recipeName, $author, $allSteps, $privacy, $recipeId); //fixFlag($conn, $oldRecipeId); //if error in inserting recipe into db if ($recipeId < 0) { exit("Sorry, could not access database when adding recipe. Please try again."); }