MidgardTree Posted January 28, 2010 Share Posted January 28, 2010 Hey- I've got a form that has a dropdown generated from php: <?php echo "$TypesDD" ?> $TypesDD is defined in an included php file from a mySQL db. Pertinent part is: $TypesDD = "<select name=\"TypesDD\" id=\"TypeDD\">"; . . . while($row = mysql_fetch_row($result)) if($lasttype != $row[0]){ $TypesDD .= '<option value='; $TypesDD .= $row[0]; if ($row[0]==$type) $TypesDD .= ' selected'; $TypesDD .= ">" ; $TypesDD .= $row[0]; $TypesDD .= "</option>"; $lasttype = $row[0]; } After the form is submitted, I get it by saying: $type =$_POST["TypesDD"] ; Everything works great...UNTIL there is a two-word (or more, I suppose) item in the list & the post only gets the first word (leaves out the space & everything after it)... I've tried a _wide_ variety of single & double quotes in most every different place (the POST originally had single quotes, which I usually use), escaping, not escaping, nothing seems to work... What am I doing wrong?!? Any help GREATLY appreciated! -Midgard Link to comment https://forums.phpfreaks.com/topic/190080-dropdown-only-posting-until-first-space/ Share on other sites More sharing options...
Yucky Posted January 28, 2010 Share Posted January 28, 2010 I'm a little bit confused about your code example, so I'll presume you're just wanting to generate a select menu based on your database records and for it to auto select the correct value later on. If I've misunderstood, apologies. <select name="TypesDD" id="TypeDD"> <?php $i = 0; while($row = mysql_fetch_row($result)) { if ($type == $row[$i]) { echo "<option value=\"".$row[$i]."\" selected>".$row[$i]."</option>"; } else { echo "<option value=\"".$row[$i]."\">".$row[$i]."</option>"; } $i++; } ?> </select> Hope that's of some use! Edit: Would I be correct in saying you don't have a key for the options? Rather than using the full text, it'd be better to number all of your options and then have the text you want displayed in another column. Link to comment https://forums.phpfreaks.com/topic/190080-dropdown-only-posting-until-first-space/#findComment-1002940 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.