0

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

1 Answers1

0

Checkout one of the WAMP examples. http://www.homeandlearn.co.uk/php/php1p3.html

aslavkin
  • 214
  • 1
  • 7
  • I know WAMP,,but problem is i need to call api from php – prithvi t Feb 27 '17 at 07:09
  • Correct me if I missing something but php is your API script. You call it from front page by some js that was triggered by html expression. something like this: http://stackoverflow.com/questions/31193042/how-to-execute-php-function-on-html-button-click – aslavkin Feb 27 '17 at 07:14