发布数据变量太多? [英] Too Many Post Data variables?

查看:75
本文介绍了发布数据变量太多?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我第一次发布问题:

It's my first time posting a question:

我正在开发一个WordPress插件,该插件允许用户在数据库中创建数据行.当有许多行(最多100条)要由表单更新的数据时,我遇到了一个问题.每行数据包含八个POST数据变量,因此,当表单中有100行时,将发送800多个post变量.但是,只有一定数量的变量会更新数据库,目前只有112行会更新.我不知道什么会阻止该功能完成对数据库的更新.似乎我超载了太多的发布变量或发布数据大小?

I'm working on a WordPress plugin that allows the user to create rows of data in the database. I'm experiencing a problem when there are many (upwards of 100) rows of data to be updated by a form. Each row of data holds eight POST data variables, so when there are 100 rows in the form, over 800 post variables are sent. However, only a certain number of the variables update the database, right now only 112 rows update. I can't figure out what would stop the function from completing the update to the database. It almost seems like I'm overloaded with too many post variables or post data size?

使用更少的条目,一切都可以完美运行,但是一旦超过100行,一切就会停止.

Everything works perfectly with fewer entries, but once it goes over 100 rows, things stop working.

这是我的表结构:

$sql2 = "CREATE TABLE IF NOT EXISTS $item_table (
    id smallint(5) NOT NULL AUTO_INCREMENT,
    menu smallint(5) NOT NULL,
    itemorder smallint(5) NOT NULL,
    item text NOT NULL,
    description text,
    image tinytext NOT NULL,
    value tinytext NOT NULL,
    value2 tinytext NOT NULL,
    UNIQUE KEY id (id)
    ) $charset_collate;";
}

这是我的POST数据处理函数:

Here is my POST data handler function:

foreach($_POST['id'] as $i){

    $image = $_POST['image'][$i];
    $item = $_POST['item'][$i];
    $desc = $_POST['desc'][$i];
    $value = $_POST['value'][$i];
    $value2 = $_POST['value2'][$i];
    $order = $_POST['order'][$i];

    if ($_POST['strike'][$i] == 'checked' ){
        $wpdb->query( $wpdb->prepare("DELETE FROM $item_table WHERE id = $i") );
    }
    else{
        $wpdb->update( $item_table, array(
            'image' => $image,
            'item' => $item,
            'itemorder' => $order,
            'description' => $desc,
            'value' => $value,
            'value2' => $value2
         ),
         array( 'id' => $i ) );
        }
    }

    //Sort items by order, then rewrite the order with no gaps left from deleted items
    $targetmenu = $_POST['targetmenu'];

    $rows = "SELECT * FROM $item_table WHERE menu = $targetmenu ORDER by itemorder ASC";
    $result = $wpdb->get_results($rows);
    $n = 1;
    foreach ($result as $r){
        $id = $r->id;
        $wpdb->update( $jsrm_item_table , array( 'itemorder' => $n ), array( 'id' => $id ) );
        ++$n;
    }
    $loc = "&mode=editmenu&targetmenu=".$targetmenu;

    header("Location:".JSRM_SELF.$loc);
    exit(); 

}

这是我的PHP表单:

$the_menu = $wpdb->get_row("SELECT * FROM $menu_table WHERE id = $_GET[targetmenu]");
$menuid = $the_menu->id;

$q = "SELECT * FROM $item_table WHERE menu = $menuid ORDER by itemorder ASC";
$result = $wpdb->get_results($q);
if ($result) {
?>
<form id="edit-menu-form" action="<?php echo _SELF; ?>" method="post">
    <input type="hidden" name="targetmenu" value="<?php echo $menuid; ?>">
    <input type="hidden" name="dbtouch" value="updateitems">

<table>
    <?php
    foreach ($result as $r) {
        $order = $r->itemorder;
        $image = $r->image;
        $imagesrc = ($image) ? esc_html(stripslashes($r->image)) : 'addimage.jpg';
        $item = esc_html(stripslashes( $r->item ));
        $description = esc_html(stripslashes($r->description));
        $value = esc_html(stripslashes($r->value));
        $value2 = esc_html(stripslashes($r->value2));
        $id = $r->id;
    ?>

    <tr id="<?php echo $id ?>">
        <td><?php echo $order ?></td>
        <td><a class="edit-item-img" id="item-image-<?php echo $id ?>" style="background-image:url(<?php echo $imagesrc ?>);" title="Edit image"></a>
            <input type="hidden" name="image[<?php echo $id ?>]" id="field-item-image-<?php echo $id ?>" value="<?php echo $image ?>" />
            <img class="remove-image-button" id="image-<?php echo $id ?>" src="removeimage.png"
                <?php if(!$image){ ?> 
                    style="visibility:hidden;" 
                <?php } ?>
            />
        </td>
        <td><textarea name="item[<?php echo $id ?>]"><?php echo $item ?></textarea></td>
        <td><textarea name="desc[<?php echo $id ?>]"><?php echo $description ?></textarea></td>
        <td><input type="text" name="value[<?php echo $id ?>]" value="<?php echo $value ?>" /></td>
        <td><input type="text" name="value2[<?php echo $id ?>]" value="<?php echo $value2 ?>" /></td>
        <td><input type="checkbox" class="strike" name="strike[<?php echo $id ?>]" value="checked"/></td>
        <input type="hidden" name="order[<?php echo $id ?>]" value="<?php echo $order ?>" id="order<?php echo $id ?>"/>
        <input type="hidden" name="id[<?php echo $id ?>]" value="<?php echo $id ?>" id="id<?php echo $id ?>"/>
    </tr>

    <?php
    }
    ?>  
</table/>
<p><input type="submit" id="update-items-button" value="Update All" class="button-primary"/></p>
</form>

<?php
}   
?>

推荐答案

我今天遇到了类似的问题.我有一个包含250+行和每行5个变量的表单,但是$ _POST变量似乎被截断了.就我而言,它在1000个元素后就停止了.

I had a similar problem today. I had a form with 250+ rows and 5 variables per row, but the $_POST variable appeared to be truncated. In my case, it stopped after 1000 elements.

有一个名为max_input_vars的PHP设置,默认为1000.此设置为将要放入PHP脚本的变量数量设置了上限.您可能需要在服务器设置上增加此值,以使页面正常工作.通过增加此值,我可能无法完全理解某些安全隐患,这可能导致拒绝服务攻击.

There is a PHP setting called max_input_vars that defaults to 1000. This setting sets an upper limit on how many variables it will pull into your PHP script. You may need to increase this value on your server settings to make your page work. There are some security implications that I don't fully understand with increasing this value that could enable a denial of service attack.

由于您正在开发Wordpress插件,您可能需要查看是否存在更改表格的方式以减少发送的变量数量,因为您可能无法为使用该插件的用户更改服务器配置.

Since you are developing a Wordpress plugin, you may need to see if there are ways to change your form to reduce the number of variables you send, because you probably can't alter server configurations for people using your plugin.

在此处详细了解设置: http ://www.php.net/manual/zh-CN/info.configuration.php#ini.max-input-vars

Read more about the setting here: http://www.php.net/manual/en/info.configuration.php#ini.max-input-vars

这篇关于发布数据变量太多?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆