Webbserverprogrammering 1

Show sourcecode

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

ramverket/exercises/ajax/

ajax_api.php
ovn_ajax1.php
ovn_ajax2.php
ovn_ajax3.php

ajax_api.php

15 lines ASCII Windows (CRLF)
<?php 
  $remote 
= false;
  include(
"../../incl/connect_db.php");
  
$name = $_POST['name'] ?? null;

  if (
$name === null || $name === '') {
    echo 
json_encode([]);
    exit();
  }

  
$sql = "SELECT * FROM ajax WHERE name LIKE ?";
  
$stmt = $conn->prepare($sql);
  
$stmt->execute(["%$name%"]);
  echo 
json_encode($stmt->fetchAll());
?>