0

I know these kinds of question has been asked multiple times in SO. But i am getting error in below code.

I have a form in modal box.

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

Here is the code for form submit. Which is on the same page.

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();

    }

When i submit the form data is not getting saved in database. I am not sure what am i doing wrong. Please advise.

Please ignore typos.

Roxx
  • 3,738
  • 20
  • 92
  • 155
  • 1
    What error are you getting? You don't have a form element named 'comment', so $_POST['comment'] will be empty. You'll want to check all of your form elements to make sure they have name attributes. – Jay Blanchard Jun 25 '16 at 16:42
  • i am not getting any error. Data is not saving in database and modal box get closed. Ok @JayBlanchard i will fix that but no records is getting added in database. – Roxx Jun 25 '16 at 16:44
  • @JayBlanchard i don't think comment is not defined. If you check the code below select box there is comment defined. And i don't think this is the reason for form submit. Anyways thanks for marking it duplicate. – Roxx Jun 25 '16 at 16:51
  • Here should also be the name not only id , here ` – Niklesh Raut Jun 25 '16 at 16:55
  • @Rishi it is placed in original code. i am updating it in question. – Roxx Jun 25 '16 at 16:56
  • 1
    It is totally undefined because it does not have a name attribute. ***All*** form elements must have a name attribute. If you're not seeing errors you need to open your we server's error logs. – Jay Blanchard Jun 25 '16 at 16:56
  • Thanks @JayBlanchard Silly mistake i did. Checking the code. Earlier i thought by using ID it will work. – Roxx Jun 25 '16 at 16:59
  • I put name and id in form but still i think something is missing. Because data is still getting saved in database. – Roxx Jun 25 '16 at 17:03

0 Answers0