php - Inserting data into database using ajax -


i trying insert data database using ajax reason code not doing that. here have far:

index page:

<form id="notify" action="" method="post" accept-charset="utf-8" enctype="multipart/form-data">     <div class="note-wrapper">         <div class="note-title">new employee</div>         <input type="hidden" name="employee_id" value="<?php echo $employee_id; ?>" id="employee_id">         <p>name</p>         <input type="text" name="name" id="name">         <p>description</p>         <textarea name="text" id="text"></textarea>         <div class="action-wrapper">             <button class="cancel-btn">cancel</button><button class="submit-btn flt-rt" type="submit" name="new_note">add</button>         </div>     </div>   </form>  <script type="text/javascript">  $('#notify').submit(function() {     var employee_id = $('#employee_id').val();     var name = $('#name').val();      $.ajax({         type: 'post',         data: {employee_id:employee_id, name:name},         url: 'notify',         success: function(data) {             alert(data);         }     });  });  </script> 

when script run error page displayed when cannot find page requested have notify page created , can access through browser when manually point it.

notify page:

<?php ini_set('display_errors', "off");  $employee_id = $_post['employee_id']; $note_name = $_post['name'];  if(!empty($employee_id)) {     $objbreeze = new breeze();      $objbreeze->createemployee($employee_id, $note_name);  } 

breeze class:

<?php  class breeze extends application {      private $table_2 = 'employee';      public $path = 'media/';      // notes crud     public function createemployee(array $params) {         if(!empty($params)) {             $params['date'] = helper::setdate();             $this->db->prepareinsert($params);             $output = $this->db->insert($this->table_2);             $this->id = $this->db->id;             return $output;         }         return false;     }      public function getemployee() {          $query = "select * {$this->table_2} order `date` desc";         return $this->db->fetchall($query);      } 

the above database crud works fine on other projects. if has clue doing wrong grateful friends.

your notify script calling breeze::createemployee incorrectly. method expects array parameter , passing 2 scalar variables

<?php ini_set('display_errors', "off");  $employee_id = $_post['employee_id']; $note_name = $_post['name'];  if(!empty($employee_id)) {     $objbreeze = new breeze();      //$objbreeze->createemployee($employee_id, $note_name);     //                           ^^^^^^^^^^^^^^^^^^^^^^^^      // guess need somthing     // have guess dont show      // $this->db->prepareinsert($params);      $params = array('employee_id' => $_post['employee_id'],                      'name' => $_post['name']);     $objbreeze->createemployee($params); } 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -