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
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'];

Link to comment
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'];

 

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)? 

Link to comment
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.