I have provided complete PDO code for your current scenario that is inserting data into table and then getting information of last inserted record. For better understandings you should have to look into PHP PDO Class. Its really simple, easy and you can find a lot of things on this topic.
<?php
//Specifying database credentials
$dbhost = "localhost";// Your host name
$dbname = "test"; // Your database name
$dbuser = "root"; // database user
$dbpass = "";// Database password
$Name = $_POST["Name"];
$Age = $_POST["Age"];
$RecordDate = date("d-M-Y h:i:s a");
$jTableResult = array();
//Establishing connection to the database
try
{
$db = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);
} catch (PDOException $e) {
print "Error!: " . $e->getMessage();
die();
}
$sql = "INSERT INTO people(Name, Age, RecordDate) VALUES (:Name, :Age, :RecordDate)";
$statement = $db->prepare($sql);
//Bindging values to be added to People table
$statement->bindParam(":name", $firstname );
$statement->bindParam(":Age", $Age );
$statement->bindParam(":RecordDate", $RecordDate );
if($statement->execute()) // Check if insert statement executed successfully
{
$PersonId = $db->lastInsertId(); // Getting Last inserted id;
$get_statement= $db->prepare("SELECT * FROM people WHERE PersonId=:PersonId");
$get_statement->bindParam(":PersonId", $PersonId );
$get_statement->execute(array(':Uemail'=>$email, ':Upassword'=>$password));
if($row=$get_statement->fetch(PDO::FETCH_ASSOC)) // as we are getting only one record, therefore fetch() method is best. The fetchAll should be used if you are getting multiple records
{
$jTableResult['Result'] = "OK";
$jTableResult['Record'] = $row;
print json_encode($jTableResult);
}
else
{
echo json_encode("Error");
}
}
else
{
$jTableResult['Result'] = "FAIL";
$jTableResult['Record'] = array();
print json_encode($jTableResult);
}
?>