Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用php rest api将Html连接到Mysql_Php_Html_Mysql_Api - Fatal编程技术网

使用php rest api将Html连接到Mysql

使用php rest api将Html连接到Mysql,php,html,mysql,api,Php,Html,Mysql,Api,我有一个html表单,有两个字段Name和Age,我创建了一个MySQL数据库,当使用php API提交到数据库时,我需要存储html中的值。。。 我熟悉php,但当表单提交时,我需要使用API从html页面发送值…我用于html和API的代码 Index.html <form class="col s12" method="post" action=""> <input id="name" type="text" name="Name"> <input id="n

我有一个html表单,有两个字段Name和Age,我创建了一个MySQL数据库,当使用php API提交到数据库时,我需要存储html中的值。。。 我熟悉php,但当表单提交时,我需要使用API从html页面发送值…我用于html和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>

现在我想知道,当提交html表单时,我应该进一步做些什么来将值发送到db

签出WAMP示例之一。

我知道WAMP,,但问题是我需要从phpCorrect调用api,如果我遗漏了什么,但php是您的api脚本,请更正我。您可以通过一些由html表达式触发的js从首页调用它。大概是这样的:
$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
    } 
});