无法使用jquery ajax post方法将远程加载的表单数据发布到数据库

时间:2013-06-14 08:40:36

标签: php jquery sql html5

Gudday伙伴们,我在使用jquery的load()方法远程加载表单后,将表单成功发布到数据库时遇到了一些挑战,它在谷歌浏览器中工作但不能使用firefox.Thanks预期你的帮助。

PHP代码。

<?php
        include 'login.php';
  if( isset($_POST['c_title']) && isset($_POST['c_code']) && isset($_POST['staff_id'])&& isset($_POST['staff_fulname'])
  && isset($_POST['c_desc'])&& isset($_POST['unit']) ){

      $c_title = sanitize_string($_POST['c_title']);
      $c_code = sanitize_string($_POST['c_code']); 
      $staff_id = sanitize_string($_POST['staff_id']);
      $staff_fulname= sanitize_string($_POST['staff_fulname']); 
      $c_desc = sanitize_string($_POST['c_desc']);
      $unit = sanitize_string($_POST['unit']); 



      $sql = " insert into course values('$c_title','$c_code','$staff_id','$staff_fulname','$c_desc','$unit') ";

      $result = mysql_query($sql);

      if($result){
        // echo '<br/> <div align="center"><small class="alert alert-success">&radic; Saved Successfully!</small></div>';
        echo '<script>alert("Saved Successfully!");</script>';
      }
      else{
          echo '<script>alert("Error Occured!");</script>';
      }



  }

   function sanitize_string($var){
    $var = mysql_real_escape_string($var);
    $var = htmlentities($var);
    $var = stripslashes($var);

    return $var;
   }
  ?>

<body>




<div class="container5">
<div align="center"><h3 class="btn-danger">Course Details</h3></div>
<div class="row">

<div class="span12">

<br/>
<div class="row">
<form id ="course_form" action="" method="post">
<div class="span6">
<div align="center">
Course Title:<input type="text" name="c_title" required/>
</div></div>

<div align="right">
<div class="span6">
Course Code:<input type="text" name="c_code" required/>
</select>
</div>
</div></div></div>
</div>

<div class="row">

<div class="span12">

<div class="row">


<div class="span6">
<div align="center">
Staff ID:<input type="text" name="staff_id" required/>
</div></div>
<div class="span6">
<div align="right">
Staff FullName:<input type="text" name="staff_fulname" required/>
</div></div>
<br/>
</div></div></div>

<div class="row">

<div class="span12">

<div class="row">


<div class="span6">
<div align="center">
Course Description:<textarea name ="c_desc" rows="3"></textarea>
</div></div>
<div class="span6">
<div align="right">
Unit Load:<select name="unit"> <option>1</option><option>2</option><option>3</option><option>4</option><option>6</option> </select></div>
</div>
<br/>
</div></div></div>

<div align="center"><button id="save2" class=" btn btn-danger">Save</button>
</form>

</div>
</body>

<script>
$(document).ready(function() {
$("#save2").click(function(){
            $.ajax({
            type: "POST",
        url: "course.php",
        data: $('#course_form').serialize(),
            success: function(msg){
                  alert("Saved Successfully");
                },
        error: function(){
            alert("Error has occurred");
            return
        }
            });
         })
});
         </script>

0 个答案:

没有答案