I have an html form with 2 fields Name and Age and I created a MySQL Database and i need to store values from html when submitted to my database using php API... I am familiar with php but i need to use API to send values from html page when form submitted...Code I used for html and API.
Index.html
<form class="col s12" method="post" action="">
<input id="name" type="text" name="Name">
<input id="name" type="text" name="Age">
<button type="submit" name="btn_login">Request</button>
</form>
reg.php(api)
$app->post('/createstudent', function () use ($app) {
verifyRequiredParams(array('Name', 'Age'));
//Creating a response array
$response = array();
//reading post parameters
$name = $app->request->post('Name');
$age = $app->request->post('Age');
//Creating a DbOperation object
$db = new DbOperation();
//Calling the method createStudent to add student to the database
$res = $db->createStudent($name,$age);
//If the result returned is 0 means success
if ($res == 0) {
//Making the response error false
$response["error"] = false;
//Adding a success message
$response["message"] = "You are successfully registered";
//Displaying response
echoResponse(201, $response);
//If the result returned is 1 means failure
} else if ($res == 1) {
$response["error"] = true;
$response["message"] = "Oops! An error occurred while registereing";
echoResponse(200, $response);
//If the result returned is 2 means user already exist
}
});
Now I want to know what i should do further to send values to db when html form submitted