save values from editable table using php

后端 未结 3 2209
攒了一身酷
攒了一身酷 2021-02-09 14:58

Hi I have a table generated from php, it is editable, I want to save edited values to database. I have no Idea how can I do this as there are many rows(dynamic) on a page. Here

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-09 15:15

    Let me give you with the best way First your database tables have spaces: correct that e.g.

    from $row["Initial Stock"] to $row["Initial_Stock"]

    Then i will propose you use ajax instead of wasting time clicking buttons

    The HTML Page

    
     
    
    
    
    
     
    "; fetch_assoc()) ?>
    Sl Number Product Id Product Name Product Catagory Retal Price Max Price Min Price Initial Stock Quantity Sold Current Stock Last Order Edit/Update
    "> "> "> "> "> "> "> "> "> "> ">

    And the update php page

        false,
                      PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
    
    
    ?>
    
     $val)
        {
            //clean post values
            $field_id = strip_tags(trim($field_name));
    
            //from the fieldname:user_id we need to get user_id
            $split_data = explode(':', $field_id);
            $product_id = $split_data[1];
            $field_name = $split_data[0];
            if(!empty($product_id) && !empty($field_name) && !empty($val))
            {
    
                $affected_rows = $db->exec("UPDATE yourtable SET $field_name = '$val' WHERE product_ID = $product_id");
                echo $affected_rows;
    
                echo "Updated";
            } else {
                echo "Invalid Requests";
            }
        }
    } 
    
    else {
        echo "Invalid Requests";
    }
    ?>
    

提交回复
热议问题