Jump to content

getting variable $_POST


havik

Recommended Posts

hello,

 

on a form i got this code

<?php
        //opzoeken aantal max toegelaten claims
        $opzoeken = "select waarde FROM ".$db_pf."config WHERE conf = 'max'";
        $resultaat = mysql_query($opzoeken);
        $maxcl = mysql_fetch_object($resultaat);
        //vaste variable om reeks aan te maken
        $teller = "1";
        $maxclaims = ($maxcl->waarde);
        //weergave van een nieuwe claimlijn zolang als $teller niet groter is dan het max aantal claims
        while ($teller <= $maxclaims) {
        //aanpassen van variable cordx en corxy ifv aantal claim lijnen
        echo "<tr><td>claim ".$teller."</td><td colspan = 2><input type='text' name='cordx".$teller."' size='3'>|<input type='text' name='cordy'".$teller." size='3'></td></tr>";
        //teller verhogen
        $teller ++;
        }

        ?>

 

as u can see the varibles cordx and cordy get a number behind them depending on the value of $teller

my problem is that when the user submids the data i need a way to get all the $_POST['cordx(number)'] and $_POST['cordy(number)']

i know i can start the same way with a while loop but how can i chane the number in the $_POST variable

 

hope i'm making sence here , and ty for reading

Havik

 

Link to comment
https://forums.phpfreaks.com/topic/126323-getting-variable-_post/
Share on other sites

Putting [$teller] after the name causes the fields to be posted as an array with $teller as the key.

 

Run this sample script, it may help you to see what happens

 

<?php
if (isset($_POST['btnSubmit']))
{
    echo "<p>Posted data</p>";
    echo '<pre>', print_r($_POST, true), '</pre>';
    echo "<p>Processing posted data</p>";
    foreach ($_POST['cordx'] as $teller => $cordx)
    {
        // get matching cordy
        $cordy = $_POST['cordy'][$teller];
        
        echo "Teller $teller coords are $cordx, $cordy <br/>";
    }
    exit;
}

echo '<form method="POST">';
$x = 10;
$y = 100;

for ($teller=1; $teller <= 3; $teller++)
{
    // input fields for each teller
    echo "Teller $teller : X <input type='text' name='cordx[$teller]' value='$x' size='5'> 
          Y <input type='text' name='cordy[$teller]' value='$y' size='5'>
          <br/>";
    $x += 10;
    $y += 100;
}
echo "<input type='submit' name='btnSubmit' value='Submit'> ";
echo '</form>';
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.