projecte_ionic_entrega_02/src/backend/insert.php

60 lines
1.9 KiB
PHP
Executable file

<?php
include "config.php";
$response = array();
$name = $_POST["countryName"];
$continent = $_POST["countryContinent"];
$area = $_POST["countryArea"];
$population = $_POST["countryPopulation"];
$drivingSide = $_POST["countryDrivingSide"];
// $flag = $_FILES["countryFlag"];
// $target_dir = "../assets/img/flags/";
// $target_file = $target_dir . fileNamer();
// $uploadOk = 1;
// $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// // Check if image file is a actual image or fake image
// if(true) {
// $check = getimagesize($flag["tmp_name"]);
// if($check !== false) {
// echo "File is an image - " . $check["mime"] . ".";
// $uploadOk = 1;
// } else {
// echo "File is not an image.";
// $uploadOk = 0;
// }
// if (move_uploaded_file($flag["tmp_name"], $target_file)) {
// echo "The file ". htmlspecialchars( basename( $flag["name"])). " has been uploaded.";
// $response["message"] = "OK";
// } else {
// echo "Sorry, there was an error uploading your file.";
// }
// }
$sqlString = "INSERT INTO cs_countries (cs_country_name, cs_country_continent, cs_country_area, cs_country_population, cs_country_drivingSide)";
$sqlString .= " VALUES ('$name', '$continent', $area, $population, '$drivingSide')";
$sql = mysqli_query($con, $sqlString);
if($sql){
$response["message"] = "OK";
}else{
$response["message"] = "KO";
}
// function fileNamer(){
// $today = date('YmdHi');
// $startDate = date('YmdHi', strtotime('2012-03-14 09:06:00'));
// $range = $today - $startDate;
// $rand = rand(0, $range);
// return $startDate + $rand;
// }
// $response["message"] = "OK";
echo json_encode($response);
echo json_encode($_POST);
// echo json_encode($_FILE);
?>