Jump to content

[SOLVED] dynamic form issue


live_ex3me

Recommended Posts

hi there,

 

i have this form, with 2 fields for each mysql result:

 

while($row = mysql_fetch_array($res)){
       print '
        <input type=text name=order class=box size=5 value="'.$row['order'].'">
        <input type=hidden name="id_mod" value="'.$row['id_mod'].'">
      ';
}

 

saying that i have 3 sql results, i'll get from my form something like that: "?order=1&id_mod=2&order=2&id_mod=4&order=3&id_mod=5" .

 

and evan if they would not have same name, how will i use them in a new sql request ?

 

i've tryed something like this:

 

<?php
$names = "";
if (isset($_POST['fieldname'])) {  $names = $_POST['fieldname'];  }
foreach ($names as $value ) {
  echo $value . "<br/>";
}
?>

 

, but didn't work.. :(

Link to comment
https://forums.phpfreaks.com/topic/75341-solved-dynamic-form-issue/
Share on other sites

If you are doing a GET request

?order=1&id_mod=2&order=2&id_mod=4&order=3&id_mod=5
then you need to make them arrays, e.g.

?order[]=1&id_mod[]=2&order[]=2&id_mod[]=4&order[]=3&id_mod[]=5

Then you can utilise them in PHP properly.

 

To see what you're passing over :

print_r($_GET['order];
print_r($_GET['id_mod'];

If you are doing a GET request

?order=1&id_mod=2&order=2&id_mod=4&order=3&id_mod=5
then you need to make them arrays, e.g.

?order[]=1&id_mod[]=2&order[]=2&id_mod[]=4&order[]=3&id_mod[]=5

Then you can utilise them in PHP properly.

 

To see what you're passing over :

print_r($_GET['order];
print_r($_GET['id_mod'];

 

thanks.. i'll try it right now :)

 

LE:  i changed       

<input type=text [b]name=order [/b]class=box size=5 value="'.$row['order'].'">
<input type=hidden [b]name="id_mod"[/b] value="'.$row['id_mod'].'">

 

with

<input type=text [b]name="order[]"[/b] class=box size=5 value="'.$row['order'].'">
<input type=hidden [b]name="id_mod[]"[/b] value="'.$row['id_mod'].'">

 

but now it looks like

 

?order%5B%5D=1&id_mod%5B%5D= ...

 

if i use POST, the code ugave me would look different (exept post instead of get)? 

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.