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

start.php

73 lines UTF-8 Windows (CRLF)

<?php
session_start
();
include(
'../../dbconnection.php');
ob_clean();

include(
'include/session-variables.php');


?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="css/styles.css">
  <title>Start</title>
</head>
<body>
  <div id="page-container">
    <div id="content-wrap">
      <?php
      
include('include/header.php');
      
?>
      <main>
        <h1>Vad vill du koka idag?</h1>
        <form id="searchForm" action="" method="get">
          <div class="center">
            <input type="search" id="searchbar" placeholder="Sök recept eller kategori" aria-label="Sök">
          </div>
        </form>

        <div id="results-container">
          <div id="results">
          </div>
        </div>
      </main>


      <?php
        
include('include/footer.php');
      
?>
    </div>
  </div>

  <script>
    const searchInput = document.getElementById('searchbar');
    const searchForm = document.getElementById('searchForm');

    searchInput.addEventListener('keyup', function () {
      showRecipes(this.value);
    });

    searchForm.addEventListener('submit', function (event) {
      event.preventDefault();
      showRecipes(searchInput.value);
    });

    async function showRecipes (str){
      if (str.length < 2) {
        document.getElementById("results").innerHTML = "";
      }
      else {
        let myObject = await fetch("recipe-search.php?recipe=" + str);
        let myText = await myObject.text();
        document.getElementById("results").innerHTML = myText;
      }

    }
  </script>
</body>
</html>