dongzai0020 2018-08-04 04:49
浏览 72
已采纳

使用jquery将数据插入mysql时出错

I am new to jquery ,i have some trouble while inserting data to mysql database using jquery. this is my html file

<!DOCTYPE html>
<html>
<head>
<title>
staff registration
</title>
<body>
<form>
Staff Id:<input type="text" id="staffid"><br>
Password:<input type="password" id="password1"><br>
Re-enter Password:<input type="password" id="password2"><br>
Email:<input type="email"   id="email"><br>
Gender:<input type="text" id="gender"><br>
Qualification:<input type="text" id="qualification"><br>
Course 1:<input type="text" id="course1"><br>
Course 2:<input type="text" id="course2"><br>
Course 3:<input type="text" id="course3"><br><br>
<input type="submit" id="submit" value="CREATE">
</form>
<script src="jquery.min.js"></script>
<script>
$("#submit").click(function(){
 var staffid=$("#staffid").val();
 var password1=$("#password1").val();
 var password2=$("#password2").val();
 var email=$("#email").val();
 var gender=$("#gender").val();
 var qualification=$("#qualification").val();
 var course1=$("#course1").val();
 var course2=$("#course2").val();
 var course3=$("#course3").val();
 $.post("insert.php",{si:staffid,pwd1:password1,pwd2:password2,
 email:eml,gender:gen,qualification:qal,course1:c1,course2:c2,course3:c3},
 function(data){
     alert(data);
 }); 
});
</script>
</body>
</html>

this is my php file named insert.php

<?php
 $con=new mysqli("localhost","root","","flash");
    $si=$_POST['si'];
    $pwd1=$_POST['pwd1'];
    $pwd2=$_POST['pwd2'];
    $eml=$_POST['eml'];
    $gen=$_POST['gen'];
    $qal=$_POST['qal'];
    $c1=$_POST['c1'];
    $c2=$_POST['c2'];
    $c3=$_POST['c3'];
    $sql="INSERT INTO staff(staff_id,password,email_id,gender,qualification,course_1,course_2,course_3) VALUES('$si','$pwd2','$eml','$gen','$qal','$c1','$c2','$c3')";
    $con->query($sql);

?>

nothing will happen while i click submit button

please anyone help me to solve this issue

展开全部

  • 写回答

1条回答 默认 最新

  • dptdb84606 2018-08-04 05:29
    关注

    Try to use the non-slim build, available here http://jquery.com/download/, such as:

    https://code.jquery.com/jquery-3.3.1.min.js

    Also you had issue while making the json for the post, here is the rectified version

    <!DOCTYPE html>
    <html>
    <head>
    <title>
    staff registration
    </title>
    <body>
    <form>
    Staff Id:<input type="text" id="staffid"><br>
    Password:<input type="password" id="password1"><br>
    Re-enter Password:<input type="password" id="password2"><br>
    Email:<input type="email"   id="email"><br>
    Gender:<input type="text" id="gender"><br>
    Qualification:<input type="text" id="qualification"><br>
    Course 1:<input type="text" id="course1"><br>
    Course 2:<input type="text" id="course2"><br>
    Course 3:<input type="text" id="course3"><br><br>
    <input type="submit" id="submit" value="CREATE">
    </form>
    <script
      src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
    <script>
    $("#submit").click(function(){
     var staffid=$("#staffid").val();
     var password1=$("#password1").val();
     var password2=$("#password2").val();
     var email=$("#email").val();
     var gender=$("#gender").val();
     var qualification=$("#qualification").val();
     var course1=$("#course1").val();
     var course2=$("#course2").val();
     var course3=$("#course3").val();
     $.post("insert.php",{si:staffid,pwd1:password1,pwd2:password2,
     eml:email,gen:gender,qal:qualification,c1:course1,c2:course2,c3:course3},
     function(data){
         alert(data);
     }); 
    });</script>
    </body>
    </html>
    

    展开全部

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 fluentmeshing
  • ¥15 手机/平板的浏览器里如何实现类似荧光笔的效果
  • ¥15 盘古气象大模型调用(python)
  • ¥15 传人记程序做的plc 485从机程序该如何写
  • ¥15 已知手指抓握过程中掌指关节、手指各关节和指尖每一帧的坐标,用贝塞尔曲线可以拟合手指抓握的运动轨迹吗?
  • ¥50 libwebsockets 如何添加其他socket事件回调
  • ¥50 实现画布拖拽算子排布,通过flink实现算子编排计算,请提供思路
  • ¥15 esium自定义材质拉伸问题
  • ¥15 cmake+mingw使用<mysqlx/xdevapi.h>报错
  • ¥15 eNSP中防火墙的使用
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部