1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
include_once('../data/connection.php');
$output = array('error' => false);
$database = new Connection();
$db = $database->open();
try{
//make use of prepared statement to prevent sql injection
$stmt = $db->prepare("INSERT INTO table (id_theme,id_Image,date_arrivee) VALUES (:id_theme,:date_arrivee)");
//if-else statement in executing our prepared statement
$variab = array(':id_theme' => $_POST['id_theme'] ,':id_Image' => NULL,,':date_arrivee' => date("Y-m-d"));
if ($stmt->execute($variab)){
$output['message'] = 'Route added successfully';
}
else{
$output['error'] = true;
$output['message'] = 'Something went wrong. Cannot add Route';
}
}
catch(PDOException $e){
$output['error'] = true;
$output['message'] = $e->getMessage();
}
//close connection
$database->close();
echo json_encode($output); |