dongshan3806 2012-12-01 10:04 采纳率: 0%
浏览 45
已采纳

使用php中的ajax将数据插入数据库

i do have 3 input text which are of "type:number" and a save button. i want to insert the these 3 input text data into the database using ajax. i have written the code as follows:

<fieldset><legend>Response Times</legend></fieldset> 
    <form class="form">
        <div class="control-group">
            <label class="control-label">High Priority</label>
            <div class="controls">
            <input type="number" name="high" id="sval"/>Days
            </div>
        </div>
        <div class="control-group">
            <label class="control-label ">Low Priority</label>
            <div class="controls">
            <input type="number" name="high" id="sval"/>Days</div>
        </div>
         <div class="control-group">
            <label class="control-label ">Normal</label>
            <div class="controls">
            <input type="number" name="high" id="sval"/>Days </div>
        </div>
        <button id="insert" class="btn btn-primary">Save</button>
</form>
<script type="text/javascript" src="<?php echo $BASE;?>scripts/data/projects_service.js"></script>

and my query is

Insert into app_settings(kunnr,skey,sval) Values ('0001000383','hp_days','1') 
Insert into app_settings(kunnr,skey,sval) Values ('0001000383','lp_days','3')
Insert into app_settings(kunnr,skey,sval) Values ('0001000383','np_days','2')

which are hard coded but i dont want hard coded data.my problem is that only sval values are showing in the view but what about this skey value.and i want o insert it using ajax and i have tried this by ajax that i have written as follows:

$(function () {
    $("#insert").click(function () {
        var id = $("#id").val();
        var sval = $("#sval").val();
        $.post(root + "data/projects_service?json", { pid: id, sval: sval }, function (data) { });

    });        
});

please suggest me on this..

  • 写回答

3条回答 默认 最新

  • duandun3178 2012-12-05 22:05
    关注

    In "your url" file you can access variables hp for example by $_GET['hp'].

    Can you tell me kunnr should be different parameter for different days? If they are not, then you can make the query in the following way:

    Insert into app_settings(kunnr,skey,sval) Values ('0001000383','hp_days',$_GET['hp']) 
    Insert into app_settings(kunnr,skey,sval) Values ('0001000383','lp_days', $_GET['lp'])
    Insert into app_settings(kunnr,skey,sval) Values ('0001000383','np_days',$_GET['n'])
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 nginx中的CORS策略应该如何配置
  • ¥30 信号与系统实验:采样定理分析
  • ¥100 我想找人帮我写Python 的股票分析代码,有意请加mathtao
  • ¥20 Vite 打包的 Vue3 组件库,图标无法显示
  • ¥15 php 同步电商平台多个店铺增量订单和订单状态
  • ¥15 关于logstash转发日志时发生的部分内容丢失问题
  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题