Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <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>
- $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
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement