Angular Js
let body : string = “key=create&name=” + name,
type : string = “application/x-www-form-urlencoded; charset=UTF-8”,
headers : any = new Headers({ ‘Content-Type’: type}),
options : any = new RequestOptions({ headers: headers }),
url : any = this.baseURI + “manage-room.php”;
this.http.post(url, body, options)
.subscribe((data) =>
{
// If the request was successful notify the user
if(data.status === 200)
{
this.hideForm = true;
this.sendNotification(`Congratulations the technology: ${name} was successfully added`);
this.navCtrl.setRoot(this.navCtrl.getActive().component);
}
// Otherwise let 'em know anyway
else
{
this.sendNotification('Something went wrong!');
}
});
Php
try {
if($name!="") {
$sql = “INSERT INTO eastcost_school_room(school_room_name, created) VALUES(:name, Now())”;
$stmt = $pdo->prepare($sql);
$stmt->bindParam(':name', $name, PDO::PARAM_STR);
//$stmt->bindParam(':b', $b, PDO::PARAM_STR);
//$stmt->bindParam(':b', $b, PDO::PARAM_STR);
$stmt->execute();
echo json_encode(array('message' => 'Congratulations the record ' . $name . ' was added to the database'));
}
}
// Catch any errors in running the prepared statement
catch(PDOException $e)
{
//echo $e->getMessage();
}
How to get return value from php file message