Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Humberto Sifuentes
Humberto Sifuentes
7,694 Points

Can`t get clean values in a <select><option> form...!

Hello, hopefully some of you guys can help me understand this problem. I have a form like this:

<select name="person"> <?php $query = "SELECT * FROM people"; $result = $conexion->query($query); while($row = mysqli_fetch_assoc($result)) { echo"<option value='".htmlspecialchars($row["person"])."'>". htmlspecialchars($row["person"])."</option>";
} ?>
</select>

As you can see, it takes values from a DB and echoes a number of OPTIONs as a part of a bigger form.

Data in the DB is correct. And yet a keep getting the value of $row["person"] plus some unwanted special characters. When the form is posted, a variable takes the value of the selected option:

$person = htmlspecialchars($_POST["person"]);

However, the final value of the variable is this:

Person<td><p class=

I am very confused! The PERSON column in the DB is correct. the "<td><p class=" segment is not a part of the form. And yet there it is this strange result...

Does anybody sees something I`m missing???

Thanks!!!

1 Answer

Humberto Sifuentes
Humberto Sifuentes
7,694 Points

Sorry... Never mind... Few hours of sleep latter and I found the silly mistake... :)