44 lines
1.3 KiB
PHP
44 lines
1.3 KiB
PHP
<?php
|
|
$con = mysqli_connect('localhost', 'root', '', 'zdj2');
|
|
|
|
if($_SERVER['REQUEST_METHOD'] == 'POST'){
|
|
$data = json_decode(file_get_contents('php://input'), true);
|
|
$img = $data['zdj'];
|
|
$nazwa = $data['nazwa'];
|
|
|
|
$stmt = mysqli_prepare($con, 'INSERT INTO zdj(nazwa, zdj) VALUES (?, ?)');
|
|
mysqli_stmt_bind_param($stmt, 'ss', $nazwa, $img);
|
|
|
|
if(mysqli_stmt_execute($stmt)){
|
|
echo json_encode(['status'=>'wyslane']);
|
|
} else {
|
|
echo json_encode(['status'=>'blad']);
|
|
}
|
|
}
|
|
|
|
|
|
if($_SERVER['REQUEST_METHOD'] == "GET" && isset($_GET['type'])){
|
|
$ans = mysqli_query($con, "SELECT * FROM zdj");
|
|
$json = array();
|
|
while($row = mysqli_fetch_assoc($ans)){
|
|
$json[] = $row;
|
|
}
|
|
echo json_encode($json);
|
|
}
|
|
|
|
|
|
|
|
if($_SERVER['REQUEST_METHOD'] == 'GET' && isset($_GET["id"])){
|
|
$ans = mysqli_query($con, "SELECT zdj FROM zdj WHERE id = ". $_GET["id"]);
|
|
$json = array();
|
|
if($ans){
|
|
while($row = mysqli_fetch_assoc($ans)){
|
|
$json[] = $row;
|
|
}
|
|
echo json_encode($json);
|
|
} else {
|
|
echo json_encode(["status"=>"nie ma danych"]);
|
|
}
|
|
}
|
|
|
|
?>
|