Advertisement
Guest User

Untitled

a guest
Feb 27th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. <form class="col s12" method="post" action="">
  2. <input id="name" type="text" name="Name">
  3. <input id="name" type="text" name="Age">
  4. <button type="submit" name="btn_login">Request</button>
  5. </form>
  6.  
  7. $app->post('/createstudent', function () use ($app) {
  8.  
  9.  
  10. verifyRequiredParams(array('Name', 'Age'));
  11.  
  12. //Creating a response array
  13. $response = array();
  14.  
  15. //reading post parameters
  16. $name = $app->request->post('Name');
  17. $age = $app->request->post('Age');
  18.  
  19.  
  20. //Creating a DbOperation object
  21. $db = new DbOperation();
  22.  
  23. //Calling the method createStudent to add student to the database
  24. $res = $db->createStudent($name,$age);
  25.  
  26. //If the result returned is 0 means success
  27. if ($res == 0) {
  28. //Making the response error false
  29. $response["error"] = false;
  30. //Adding a success message
  31. $response["message"] = "You are successfully registered";
  32. //Displaying response
  33. echoResponse(201, $response);
  34.  
  35. //If the result returned is 1 means failure
  36. } else if ($res == 1) {
  37. $response["error"] = true;
  38. $response["message"] = "Oops! An error occurred while registereing";
  39. echoResponse(200, $response);
  40.  
  41. //If the result returned is 2 means user already exist
  42. }
  43. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement