亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何將添加的數據從 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 關注
  • 92 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號