php:如何在同一页面上提交表单

时间:2016-06-25 16:42:19

标签: php

我知道在SO中多次询问过这类问题。但我在下面的代码中遇到错误。

我在模态框中有一个表单。

 <form method="post" action="<?php $_SERVER["PHP_SELF"];?>" role="form">
        <div class="modal-body">   
        <div class="row">
          <label class="col-xs-3 topjob_desc" for="title">Active list :</label>
          <div class="col-xs-8">
          <select class="form-control" id="title">

       <?php
            $total_view = $mysqli->prepare("SELECT id,title FROM posting where id= ?");
            $total_view ->bind_param("i", $id);
            $total_view->execute();
            $total_view->store_result();
            $total_view->bind_result($id,$name);

            while ($total_view->fetch()) {
               $name = $name;
               $id = $id;

    echo '<option value="'.$id.'">'.$name.'</option>';               
    }
?>

  </select>
</div></div>

<br />

    <div class="row">
      <label class="col-xs-3 topjob_desc" for="title1">Name</label>
      <div class="col-xs-8">
      <textarea class="form-control" rows="5" id="comment" name="comment">Message</textarea>

      </div>
    </div>

         </div>
        <div class="modal-footer">
            <input type="submit" class="btn btn-primary" id="submit" name="submit" value="Send" />&nbsp;
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
    </form>

以下是表单提交的代码。这是在同一页面上。

if (isset($_POST['submit'])) {
         $messages = $_POST['comment'];
        $id = $_POST['id'];
         $total_viewss = $mysqli->prepare("SELECT title,company_name FROM posting where emid= ? and jid=?");
            $total_viewss ->bind_param("si", $id,$jid);
            $total_viewss->execute();
            $total_viewss->store_result();
            $total_viewss->bind_result($title,$company);

            while ($total_viewss->fetch()) {
               $company = $company;
               $title=$title; 
               }

        $result = $mysqli->prepare("INSERT INTO user_messages (uid, profile_pic, company, title, id, messages,emid) VALUES (?, ?, ?, ?, ?, ?, ?)");
        $result ->bind_param("issssii", $uid, $profile_pic, $company, $title, $jid, $messages,$emid);
        $result->execute();
        $result->store_result();

    }

当我提交表单时,数据未保存在数据库中。我不知道我做错了什么。请指教。

请忽略错别字。

0 个答案:

没有答案