init
This commit is contained in:
62
index.php
Normal file
62
index.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
// Allow from any origin
|
||||
if (isset($_SERVER['HTTP_ORIGIN'])) {
|
||||
// Decide if the origin in $_SERVER['HTTP_ORIGIN'] is one
|
||||
// you want to allow, and if so:
|
||||
header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
|
||||
header('Access-Control-Allow-Credentials: true');
|
||||
header('Access-Control-Max-Age: 86400'); // cache for 1 day
|
||||
}
|
||||
|
||||
// Access-Control headers are received during OPTIONS requests
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
|
||||
|
||||
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
|
||||
// may also be using PUT, PATCH, HEAD etc
|
||||
header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
|
||||
|
||||
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
|
||||
header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
|
||||
|
||||
exit(0);
|
||||
}
|
||||
$data = json_decode(file_get_contents('php://input'), true);
|
||||
|
||||
|
||||
include 'db_connection.php';
|
||||
$conn = openCon();
|
||||
mysqli_set_charset($conn, "utf8");
|
||||
switch($_GET['name']){
|
||||
case "client":
|
||||
$q = "SELECT client.id, client.name, client.nip, client.arrear FROM client";
|
||||
$result = mysqli_query($conn, $q) or die("Problemy z odczytem danych!");
|
||||
$tab = [];
|
||||
while($row = mysqli_fetch_row($result))
|
||||
{
|
||||
$tab[]=["id"=>$row[0],"name"=>$row[1], "nip"=>$row[2], "arrear"=>$row[3]];
|
||||
}
|
||||
echo json_encode($tab);
|
||||
break;
|
||||
case "add":
|
||||
$q = "SELECT product.id, product.name, product.img FROM product";
|
||||
$result = mysqli_query($conn, $q) or die("Problemy z odczytem danych!");
|
||||
$tab = [];
|
||||
while($row = mysqli_fetch_row($result))
|
||||
{
|
||||
$tab[]=["id"=>$row[0], "name"=>$row[1], "img"=>$row[2]];
|
||||
}
|
||||
echo json_encode($tab);
|
||||
break;
|
||||
case "details":
|
||||
$q = "SELECT product.id, product.name, product.catalogPrice, product.img FROM product";
|
||||
$result = mysqli_query($conn, $q) or die("Problemy z odczytem danych!");
|
||||
$tab = [];
|
||||
while($row = mysqli_fetch_row($result))
|
||||
{
|
||||
$tab[]=["id"=>$row[0], "name"=>$row[1], "catalogPrice"=>$row[2], "img"=>$row[3]];
|
||||
}
|
||||
echo json_encode($tab);
|
||||
break;
|
||||
}
|
||||
closeCon($conn);
|
||||
?>
|
||||
Reference in New Issue
Block a user