1

A mysql query is grabbing data from my database and posts it into input fields in a table via while-loop. This works fine, all 252 expected table rows are shown. Pushing the submit button on the respective PHP page shall send the data to a calculation script and (re-) write data into the db.

Problem: Only 200 rows are coming through to the processing page. I.e. 52 lines do not come through. I have set up a quick script to check the output and this also shows that only 200 rows come through.

What I found out already: As soon as I reduce the table row by row the number of data put through is increasing. With only 3 rows (tipp_id, tipp_heim, tipp_gast) all 252 rows come through.

Is there a limit of throughput I'm not aware of? Or any ideas how to solve that problem?

Query & table (table includes 252 rows):

$records = mysqli_query($conn, "
    SELECT
        sp.spiel_id,
        sp.tore_heimteam,
        sp.tore_gastteam,
        t.match_id,
        t.tipp_heim,
        t.tipp_gast,
        t.tipp_id
    FROM 
        spielplan sp
    LEFT JOIN tipps t
        ON sp.spiel_id = t.match_id
");
while($fields = mysqli_fetch_assoc($records)) {
?>
    <tr>
        <td><input type="text" name="tipp_ids[]" value="<?php echo fields["tipp_id"] ?>"></td>
        <td><input type="text" name="goals_hometeams[]" value="<?php echo $fields["tore_heimteam"] ?>"></td>
        <td><input type="text" name="goals_guestteams[]" value="<?php echo $fields["tore_gastteam"] ?>"></td>
        <td><input type="text" name="tipp_guestteams[]" value="<?php echo $fields["tipp_gast"] ?>"></td>
        <td><input type="text" name="tipp_hometeams[]" value="<?php echo $fields["tipp_heim"] ?>"></td>
    </tr>

Script to check POST output (output = 200 rows):

$goalsHome = $_POST['goals_hometeams'];
$goalsGuest = $_POST['goals_guestteams'];
$tippHomes = $_POST['tipp_hometeams'];
$tippGuests = $_POST['tipp_guestteams'];
$tipp_id = $_POST['tipp_ids'];

$i=0;
foreach($goalsHome as $key => $ghome) {
    $i++;
    echo $ghome.";";
    echo $goalsGuest[$key].";";
    echo $tippHomes[$key].";";
    echo $tippGuests[$key].";";
    echo $tipp_id[$key].";";
    echo "<br>";
}
echo $i;
jean-max
  • 1,640
  • 1
  • 18
  • 33
mario
  • 61
  • 1
  • 8

2 Answers2

4

I believe you might be hitting your max_input_vars limit. Default is 1000.

You can solve this by editing your php.ini. (see: This post on SO)

Although I'd suggest changing the interface.

A little elaboration in the interface thing;

If you're trying to have your visitors fill out 1000+ input fields, go with the increased max_input_vars option. Period.

BUT, if the input fields are actually just a frontend mechanic, you're using them wrong (in my opinion). Input fields are what they are, INPUT fields. If you don't require input from your end-user, don't use an input field. You can use any HTML element at your disposal to show data.

If you only need one or two values from the user. Only ask for those one or two values. Maybe create a little javascript popup requesting the input you need. From there you can recalculate the data and post it back into your database with an xhttp request.

Community
  • 1
  • 1
Fyntasia
  • 1,133
  • 6
  • 19
  • Thank you @fyntasia! I need to contact my hoster as I am not able to edit php.ini. Will follow up as soon as I get an answer. – mario Jan 09 '17 at 16:33
  • Other question: How would you change that interface? Background: I need the values from the table to do some maths to them UPON request (i.e. clicking a button) and then update the respective values within the db. Please note: I'm an absolute PHP beginner, so no rocket science is expected. – mario Jan 09 '17 at 16:39
  • I've edited my comment to include my vision on the input fields. I'm not familiar with your project, so I don't know what you're trying to do. I hope things are clarified for you now. – Fyntasia Jan 09 '17 at 16:48
  • Thanks for the update. Do I understand this correctly: "1000" in max_input_vars = 1000 equals 1000 variables that are sent via POST when clicking the submit button (e.g. $_POST['goals_hometeam']? – mario Jan 09 '17 at 17:05
  • Yes, `max_input_vars` = 1000 means you can only have 1000 $_POST variables. – Fyntasia Jan 09 '17 at 17:07
  • You are probably right that I'm using the input fields wrong here. It is actually a frontend mechanic to calculate points in a betting game (user bets on a football game, the mechanic shall calculate the points a user gets for his bet according to some rules, e.g. right result = 4 points, reight winner = 3 points, reight result difference = 2 points, wrong bet = no points). As I'm new to PHP I did not see another possibility to calculate with these DB entries (fetching, calculating and then use UPDATE). If you see a better solution on how to do that, please let me know. – mario Jan 09 '17 at 17:09
  • As I have suggested. You can use a clean table with all the information and use javascript popups to request/handle user information. This information can then be submitted with xhttp. – Fyntasia Jan 09 '17 at 17:12
  • As suggested the adaption of "max_inputs_vars" made it. However, I rewrote the script to not include any input fields but handle it completely with SQL queries. Works perfectly fine. Thanks again @Fyntasia – mario Jan 10 '17 at 10:10
2

Look at your php.ini parameter max_input_vars = 2500 the default is 2500, but yours maybe set differently. I would guess that you have exceeded that with this form

Try increasing it to a value that matches a count of all your forms inputs

max_input_vars = 3500
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149