weixin_33726943 2017-02-14 06:04 采纳率: 0%
浏览 23

在ajax中编辑多个值

I am trying to edit two columns using ajax and php.My code currently edits one values(name) in my table and saves it to my database.When i add the second variable (p) my ajax call it updates both columns p and y with the same value.How do i edit the third value and assign it a different value from y.I want the two different columns to have different values in my db(columns:name and capacity)

This code edits and updates two values:

 <script type="text/javascript">
jQuery(document).ready(function() {  
        $.fn.editable.defaults.mode = 'popup';
        $('.xedit').editable();     
        $(document).on('click','.editable-submit',function(){
            var x = $(this).closest('td').children('span').attr('id');
            var y = $('.input-sm').val();
            var z = $(this).closest('td').children('span');
            $.ajax({
                url: "process.php?id="+x+"&data="+y,
                type: 'GET',
                success: function(s){
                    if(s == 'status'){
                    $(z).html(y);}
                    if(s == 'error') {
                    alert('Error Processing your Request!');}
                },
                error: function(e){
                    alert('Error Processing your Request!!');
                }
            });
        });
});
</script>

And this is what i tried to edit three values:

     <script type="text/javascript">
jQuery(document).ready(function() {  
        $.fn.editable.defaults.mode = 'popup';
        $('.xedit').editable();     
        $(document).on('click','.editable-submit',function(){
            var x = $(this).closest('td').children('span').attr('id');
            var y = $('.input-sm').val();
            var p = $('.input-sm').val();
            var z = $(this).closest('td').children('span');
            $.ajax({
                url: "process.php?id="+x+"&data="+y+"&capacity="+y,
                type: 'GET',
                success: function(s){
                    if(s == 'status'){
                    $(z).html(y);
                    $(z).html(p);}
                    if(s == 'error') {
                    alert('Error Processing your Request!');}
                },
                error: function(e){
                    alert('Error Processing your Request!!');
                }
            });
        });
});
</script>

And heres my php file(process.php)

    <?php
include("connect.php");
if
    ($_GET['id'],$_GET['capacity'] and $_GET['data'])
{
    $id = $_GET['id'];
    $data = $_GET['data'];
    $capacity = $_GET['capacity'];
    if(mysqli_query($con,"update mytable set name='$data',capacity='$data' where id='$id'")){

        echo "success";
    }

else{
echo 'failed';
}

}
?>

And my table in index.php

 <tbody>
                    <?php
                    $query = mysqli_query($con,"select * from mytable");
                    $i=0;
                    while($fetch = mysqli_fetch_array($query))
                    {
                        if($i%2==0) $class = 'even'; else $class = 'odd';

                        echo'<tr class="'.$class.'">

                            <td><span class= "xedit external-event bg-brown" id="'.$fetch['id'].'">'.$fetch['name'].'</span></td>

                            <td><span class= "xedit external-event bg-brown" id="'.$fetch['id'].'">'.$fetch['capacity'].'</span></td>

                        </tr>';                         
                    }
                    ?>
                    </tbody>
  • 写回答

2条回答 默认 最新

  • weixin_33716557 2017-02-14 06:13
    关注

    You have error in your sql query. As you not passing correct parameters. Please see below code.

    $id = $_GET['id'];
    $data = $_GET['data'];
    $capacity = $_GET['capacity'];
    
    // Check Sql
    $query = "update mytable set name='$data',capacity='$capacity' where id='$id'";
    if(mysqli_query($con,$query)){
    
      echo "success";
    } else{
        echo 'failed';
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图