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 CATIA有些零件打开直接单机确定终止
  • ¥15 请问有会的吗,用MATLAB做
  • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并—
  • ¥15 ARIMA模型时间序列预测用pathon解决
  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序,怎么查看客户esp32板子上程序及烧录地址