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 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

2 Comments

I know WAMP,,but problem is i need to call api from php
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: stackoverflow.com/questions/31193042/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.