简体   繁体   English

PHP表单数据未发送

[英]PHP Form data not sending

I wanted to add an input field, where the user can input a name for example and it would be added to the relevant table in the database. 我想添加一个输入字段,例如,用户可以在其中输入名称,然后将其添加到数据库中的相关表中。 However i want to create a new action for this, so far i have the basic input fields and submit button with the following code: 但是我想为此创建一个新的动作,到目前为止,我已经有了基本的输入字段并使用以下代码提交按钮:

public function action_mynewaction() {
     $this->auto_render = false;
     if ($this->request->is_ajax()) 
     {
     $stmt = DB::query(Database::INSERT, 'INSERT INTO `mytable` (`name`) VALUES (:Name)');
     $view = View :: factory('my/form/file_path');
     echo $view->render();
     }
    }

This is my view file where the form is displayed 这是显示表单的我的视图文件

<table cellspacing="1" cellpadding="5" class="myclass noSort">
   <thead>
      <tr>
         <th>A</th>
         <th>B</th>
         <th>C</th>
      </tr>
    </thead>
        <tfoot>
            <tr>
              <td colspan="3">&nbsp;</td>
            </tr>
        </tfoot>
         <tbody>
            <tr>
                <form action="" method="post">
                 <td>Add Name</td>
                 <td><input type="text" name="Name"></td>
                 <td><input type="submit" value="Submit">
                </form>
             </tr>
          </tbody>
   </table>

But whenever i add in my 但是每当我添加我的

$stmt->param(':Name', $_POST['name']); $ stmt-> param(':Name',$ _POST ['name']);

part it doen't show me the input/form field at all? 部分它根本不显示输入/表单字段?

Doesn't display form/input field at all 完全不显示表单/输入字段

       public function action_mynewaction() {
          $post = $this->request->post();

          $stmt = DB::query(Database::INSERT, 'INSERT INTO `mytable` (`name`) VALUES (:Name)');
          $stmt->param(':Name', $_POST['name']);
          $stmt->execute();

          $view = View :: factory('my/form/file_path');
          echo $view->render();
   }

forms data are case sensitive. 表单数据区分大小写。

Into your html you have : name="Name" and you will retrieve data with $_POST['Name'] that said if the "receiver" php page isn't the same as the one is sending put an "action" to the form. 进入您的html中,您将拥有: name="Name"并且将使用$_POST['Name']检索数据,该数据表示如果“ receiver” php页面与发送页面不同,则将“ action”发送到形成。

Please follow name convention so that it can bind corresponding element to browser get method. 请遵循名称约定,以便它将相应的元素绑定到浏览器的get方法。

    public function action_mynewaction() {
          $post = $this->request->post();

          $stmt = DB::query(Database::INSERT, 'INSERT INTO `mytable` (`name`) VALUES (:Name)');
          $stmt->param(':Name', $_POST['Name']); /* replace 'name' with 'Name' */
          $stmt->execute();

          $view = View :: factory('my/form/file_path');
          echo $view->render();
   }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM