为了账号安全,请及时绑定邮箱和手机立即绑定

如何将添加的数据从 HTML 表保存到 SQL (PHPMYADMIN)

如何将添加的数据从 HTML 表保存到 SQL (PHPMYADMIN)

PHP
慕妹3146593 2022-07-09 16:38:21
所以这是我的情况;我正在尝试保存通过填写表格添加的表中的数据,我不知道如何使用 javascript 或 ajax 将其保存到 phpmyadmin 中的数据库中。一个示例代码非常感谢。谢谢!PS:我是一个初学者,我只是在网上搜索代码并尝试利用我得到的东西。请帮助:D<html><body><div class = "inputfield">    <label>First Name:</label>    <input type="text" id="fname"><br>    <label>Last Name:</label>    <input type="text" id="lname"><br>    <label>Gender:</label>    <select name="gender" id="gender">        <option>Male</option>        <option>Female</option>    </select><br>    <label>HOURS:</label>    <input type="number" min=".5" max="12" step=".5" name="hours" id="hours" placeholder="--.5 to 12--"> <br></div><div class = "tablefield">    <table class="mtable"  id="mtable">        <tr>            <th width="27%">First Name</th>            <th width="27%">Last Name</th>            <th width="15%">Gender</th>            <th width="15%">Hour</th>            <th width="16%">Edit</th>        </tr>            </table>    <table class="sumtable">        <tr><b>            <td class="sum">TOTAL HOURS</td>            <td class="sum1" id="sumtd"></td>        </b></tr>    </table></div><div class="buttons">        <button type = "button" onclick="add1('mtable')">ADD</button>        <button type = "reset" name="reset" class="btnclr">CLEAR</button>        <button type = "button" name="save" onclick="savefunc()">SAVE</button></div><input type = "hidden" name="hid1" id="hid1"><input type = "hidden" name="hid2" id="hid2"><input type = "hidden" name="hid3" id="hid3"><input type = "hidden" name="hid4" id="hid4"><script>var sum = 0;
查看完整描述

1 回答

?
慕运维8079593

TA贡献1876条经验 获得超5个赞

我已经弄清楚了。我只是将它包含在我的循环语句的底部并添加了一个 save.php 文件。将此用作参考https://www.studentstutorial.com/ajax/insert-data


    

$.ajax({

            url: "save.php",

            type: "POST",

            data: {

                fname: hid1,

                lname: hid2,

                gender: hid3,

                hour: hid4

                },

                cache: false,

                success: function(dataResult){

                    var dataResult = JSON.parse(dataResult);

                    if(dataResult.statusCode==200){

                        alert("Save Successful!");

                    }

                    else if(dataResult.statusCode==201){

                       alert("Error occured !");

                    }

                }

        });


查看完整回答
反对 回复 2022-07-09
  • 1 回答
  • 0 关注
  • 103 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号