Jump to content

Max Post Variables


Go to solution Solved by kicken,

Recommended Posts

Im creating an online ordering form for a large selection of items, about 1700.

 

Displaying my form works perfect, but when I receive the information and try and get the post variables It stops after 330. If I start my counter at 300, it stop at 630, so there must be a limit of 330 post variables, anyone ever run into this? I'll try and post some code snippets

 

// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
//This query will return about 1700 results
$result = mysqli_query($con,"SELECT * FROM formatted");
$a = 0;
$currentCategory = "";
$status = "begin";
while($row = mysqli_fetch_array($result))
  {
	  echo $_POST['qty' . $a];
	  if(isset($_POST['qty' . $a]) && ($_POST['qty' . $a] != 0)) {
	$qty = $_POST['qty' . $a];
	$ttl = $qty * substr($row['price'],1);
	if($currentCategory != $row['subcategory'])
	  {   
    $customerInfo .= '<tr><th colspan = "7" style="background-color: #104E8B; color: #FFF;">' . $row['subcategory'] . '</th></tr>';
	$currentCategory = $row['subcategory'];
	  }
	$customerInfo .= '<tr>
      <td>' . $row['size'] . '</td>
      <td>' . $row['description'] . '</td>
      <td>' . $row['upc'] . '</td>
      <td>' . $qty . '</td>
	  <td>' . $row['price'] . '</td>
      <td>' . $ttl . '</td>
      <td>' . $_POST['notes'] .'</td>
    </tr>';
	$currentCategory = $row['subcategory'];
	  }
  $a++;
  }
  echo '</table>';

mysqli_close($con);

 

 

Link to comment
https://forums.phpfreaks.com/topic/275656-max-post-variables/
Share on other sites

  • Solution

max_input_vars

 

Yes, there is a configurable limit on how much data PHP will accept. The default is 1000 but yours may be lowered. Note that despite the manual saying This limit applies only to each nesting level of a multi-dimensional input array.", the limit is actually an overall total, not a per-array-level total.

Link to comment
https://forums.phpfreaks.com/topic/275656-max-post-variables/#findComment-1418621
Share on other sites

On an unrelated note, there is a flaw in your logic.

 

You have a loop that iterates over a query and in each iteration of the loop you are referencing specific POST variables based upon the index of $a. So, you are "assuming" that the item $_POST['qty0'] is necessarily associated with the first record in your query. This is a very poor way to associate data. Never assume that the order of items will be the same or that the number of records will be the same. Think about what would happen if someone deleted a product between the time the the form was opened and when it was submitted. Everything from where that product was in the order would be associated with the wrong product.

 

There is a much simpler and fool-proof method to handle this. 1) Make the field names arrays and 2) Use the record ID as the index for those arrays. In this case I would create the fields something like this:

 

<input type='text' name='qty[5]' />

Where '5' is the ID for the product that that field is associated with

 

Creating them dynamically might look like this

 

$result = mysqli_query($con,"SELECT id, name FROM formatted");
while($row = mysqli_fetch_array($result))
{
    echo "{$row['name']}: <input type='text' name='qty[{$row['id']}]' /><br>";
}

 

 

Now, when you receive your POST data you will be 100% certain that you are matching the POST data with the right records from your query. Also, you are only processing records from the query IF the submitted value was not 0. That is inefficient. With the revision above you can also modify your query to ONLY pull the records needed. So, no need to query 1700 records when the user only input values for 5 fields!

 

Your logic above could then be simplified to this:

 

<?php
    // Check connection
    if (mysqli_connect_errno())
    {
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }

    //Ensure POST value are integers and remove those that are 0
    $valuesAry = array_filter(array_map('intval', $_POST['qty']));
    //Create an array of the IDs from the indexes (also ensure they are ints)
    $IDsAry - array_map('intval', array_keys($_POST['qty']));

    //Query ONLY the items that had non-zero values in POST
    $query = "SELECT * FROM formatted WHERE id IN (" . implode(', ', $IDsAry) . ")";
    $result = mysqli_query($con, $query);
    $currentCategory = "";
    while($row = mysqli_fetch_array($result))
    {
        if($currentCategory != $row['subcategory'])
        {
            $customerInfo .= "<tr><th colspan = '7' style='background-color: #104E8B; color: #FFF;'>{$row['subcategory']}</th></tr>\n";
            $currentCategory = $row['subcategory'];
        }

        $qty = $valuesAry[$row['id']];
        $ttl = $qty * substr($row['price'],1);
        $customerInfo .= "<tr>\n";
        $customerInfo .= "<td>{$row['size']}</td>\n";
        $customerInfo .= "<td>{$row['description']}</td>\n";
        $customerInfo .= "<td>{$row['upc']}</td>\n";
        $customerInfo .= "<td>{$qty}</td>\n";
        $customerInfo .= "<td>{$row['price']}</td>\n";
        $customerInfo .= "<td>{$ttl}</td>\n";
        $customerInfo .= "<td>{$_POST['notes']}</td>\n";
        $customerInfo .= "</tr>\n";
    }
    echo "</table>\n";
     
    mysqli_close($con);

    ?>
Link to comment
https://forums.phpfreaks.com/topic/275656-max-post-variables/#findComment-1418634
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.