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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

php drop down menu 1

Status
Not open for further replies.

bccamp

Technical User
Jan 20, 2005
69
I'm having trouble with "'" in my drop down menu. I've got a value: "Women's Stuff" in 2 drop down menu's. One is a static javascript menu:
<option value="page.php?cat=Women's Stuff">Women's Stuff

and page.php picks up the cat with no problem.

Other menu is DB driven:
while ($author=mysql_fetch_array($result)) {
$aid=$author['name'];
$aname=htmlspecialchars($author['name']);
echo "<option value='$aid'>$aname</option>
</select><submit> so on and so on

but only ?cat=Women gets passed through. Thought about ereg_replace, but that still doesn't pass "'" through.

Where and how can I fix this?
 
You're getting caught because you're not escaping the single quote or otherwise disguising it in your "echo" statement. Using one of the following code pieces should work:
Code:
echo '<option value="' . $aid . '">' . $aname . "</option>\n";
Code:
$aid = addslashes($author['name']);
$aname=htmlspecialchars($author['name']);
echo "<option value='$aid'>$aname</option>
Code:
$aid = urlencode($author['name']);
$aname=htmlspecialchars($author['name']);
echo "<option value='$aid'>$aname</option>

Ken
 
Thanks Ken,

Used the first code and added an:
if ($q=="localhost") {ereg_replace("'","\'",$string);}
to my local server to make it work.

Yahoo doesn't need the 'if' statement, but my newer version of mysql does. Workarounds for the workarounds!

Thanks again. NEVER would have gotten that without you.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top