Webbserverprogrammering 1

Show sourcecode

The following files exists in this folder. Click to view.

webbsrvprg/projects/slutprojekt/

class/
create-categories.php
create-recipe.php
css/
db_content.php
forgot_password.php
include/
login.php
logout.php
recipe-search.php
recipe.php
reset_password.php
signin.php
start.php
tabeller/
verify.php

create-recipe.php

106 lines ASCII Windows (CRLF)
<?php
session_start
();
if(
$_SESSION['admin'] != true) {
  
header("Location: login.php");
  exit;
}
include(
'../../dbconnection.php');
ob_clean();
include(
'include/header.php');
include(
'include/session-variables.php');
include(
'class/recipeClass.php');



$recipe = new Recipe($dbconn);

$user_id $_SESSION['userId'];

?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <style>
    .current1 {
      text-decoration:underline !important ;
    }
    #content-wrap {
      text-align:center;
    }
    .select{
      width: 150px;
      height: 260px;
      font-size: 14px;
      padding: 2px;
      border-radius: 5px; 
    }
  </style>
  <link rel="stylesheet" href="css/styles.css">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Skapa Recept</title>
</head>
<body>
  <div id="page-container">
    <div id="content-wrap">
  <?php
  
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['title']) 
    && isset(
$_POST['ingredients']) && isset($_POST['instructions']) && isset($_FILES['image'])) {

    
$title trim(htmlspecialchars($_POST['title']));
    
$ingredients trim(htmlspecialchars($_POST['ingredients']));
    
$instructions trim(htmlspecialchars($_POST['instructions']));

    
$image null;
    if (
$_FILES['image']['error'] == 0) {
      
$image '../../../filhantering/' basename($_FILES['image']['name']);
      
move_uploaded_file($_FILES['image']['tmp_name'], $image);
    }

    
$categories = isset($_POST['categories']) ? $_POST['categories'] : [];

    
$recipe->createRecipe($title$ingredients$instructions$image$user_id$categories);
    echo 
"<p style='color:green;'>Receptet '$title' skapades!</p>";
  }
  
?>


  <h1>Skapa Recept</h1>
  <form action="" method="post" enctype="multipart/form-data">
    Titel:<br>
    <input type="text" name="title" size="35"  required> <br> <br>

    Ingredienser: <br>
    <textarea name="ingredients" cols="35" rows="15" required></textarea> <br> <br>

    Instruktioner: <br>
    <textarea name="instructions" cols="35" rows="15" required></textarea> <br> <br>

    Bild <br>
    <input type="file" name="image"> <br> <br>

    Kategorier <br>
    <select name="categories[]" multiple required class="select">
      <?php
      $sql 
"SELECT * FROM categories ORDER BY name ASC";
      
$stmt $dbconn->prepare($sql);
      
$stmt->execute();
      
$categories $stmt->fetchAll();

      foreach (
$categories as $category) {
        echo 
"<option value='" $category['category_id'] . "'>" $category['name'] . "</option>";
      }
      
?>
    </select><br><br>

    <input type="submit" value="Skapa Recept">
  </form>
    
  <?php
    
include('include/footer.php');
  
?>
  </div>
  </div>
</body>
</html>