Exemplo n.º 1
0
include 'db-credentials.php';
$loggedName = "";
if (isset($_SESSION['loggedin'])) {
    $loggedName = $_SESSION['username'];
}
//connect to db
$conn = connectToDb($servername, $username, $password, $dbname);
//get recipe id
$recipeId = $_GET['recipe_id'];
//get recipe name
$recipeName = getRecipeNameFromDB($conn, $recipeId);
if ($recipeName == '') {
    header('Location: fail.php');
}
//get pic name
$photoNamePrev = getImageNameFromDB($conn, $recipeId);
//get number of ingredients
$numberIngredients = getNumberOfIngredientsFromDB($conn, $recipeId);
//get each ingredient - format: ingredient1, ingredient2, ingredient3...
$ingredientList = getAllIngredientsFromDB($conn, $recipeId);
//get number of steps
$numberSteps = getNumberOfStepsFromDB($conn, $recipeId);
$stepList = getAllStepsFromDB($conn, $recipeId);
//get tags
$numberTags = getNumberOfTagsFromDB($conn, $recipeId);
$tagList = getAllTagsFromDB($conn, $recipeId);
//get flag count
$flagCount = getFlagCount($conn, $recipeId);
//get rating
$rating = getRecipeRating($conn, $recipeId);
$ratingCount = getRecipeRating($conn, $recipeId);
Exemplo n.º 2
0
 $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.");
 }
 $photoPath = NULL;
 //check if image uploaded here
 if (checkImageUploaded()) {
     $photo = getImageTmpName();
     $photoPath = getImagePath($recipeId);
     if (is_dir("images/" . $recipeId)) {
         $imagePth = getImageNameFromDB($conn, $recipeId);
         unlink($imagePth);
         rmdir("images/" . $recipeId);
     }
     if (!mkdir("images/" . $recipeId, 0777, true)) {
         exit('Could not upload image to server.');
     }
     if (!move_uploaded_file($photo, "images/" . $photoPath)) {
         exit('Could not create space on server for image.');
     }
     if (!updateImagePathInDB($conn, "images/" . $photoPath, $recipeId)) {
         exit('Could not connect image to account.');
     }
 }
 $numFriends = countFriends();
 $success = addFriendsToDB($conn, $numFriends, $recipeId);