Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

html drop down, data filled with mysql, space problem 1

Status
Not open for further replies.

treyhunsucker

Programmer
May 16, 2006
60
US
Hello,

I have a html drop down box that pulls the data from a mysql database. Everything works but there is 1 small glitch.

If the data has a space in it, ex. "Option 1", when pulling from mysql it shows up as "Option 1" in the drop down but when it's posted to the next processing page, it shows up as "Option"

I've seen examples of people using preg_replace and other functions to resolve issues like this, but none that data fill from a database.

Here is how it pulls the data:

<td>
<b>Client:</b><br>
<input type="text" name="z6" size="10" value="<? echo "$z6"?>">
<?php

$db = mysql_connect("localhost","user","pass");
mysql_select_db ("inventory");

$result = mysql_query("SELECT * FROM customer ORDER by d1")
or die(mysql_error());

echo "<select name=z6>";
echo "<option value=" . $z6 . "></option>";

while($row = mysql_fetch_array( $result )) {

echo "<option value=" . $row[d1] . ">" . $row[d1] . "</option>";
}
?>
</td><td>
 
you're code is not xhtml compliant. try this

Code:
<td>
<b>Client:</b><br>
<input type="text" name="z6" size="10" value="<? echo "$z6"?>">
<?php

$db = mysql_connect("localhost","user","pass");
mysql_select_db ("inventory");

$result = mysql_query("SELECT * FROM customer ORDER by d1")
or die(mysql_error());

echo "<select name=z6>";
echo "<option value=" . $z6 . "></option>";

while($row = mysql_fetch_array( $result )) {

echo "<option value=[red]\"[/red]$row[d1][red]\"[/red]> $row[d1]</option>";
}
?>
 
Thank you that worked. First I copied and then pasted but that didn't work, so I just typed in the changes you made in red and it worked like a charm.

Thank you again!!
 
Hi, I know it works now, but make sure you close the <select> with </select> (I didnt see it in your code).

Also, you could use htmlentites() on the data you parse..

Olav Alexander Mjelde
Admin & Webmaster
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top