Page 1 of 1

content from DB into dropdown menu (content has quotes)

Posted: Thu Oct 28, 2004 10:11 pm
by grudz
Hi,

Basically my subject askes the question...the problem isn't with how to do have content from a DB into a drop down menu, but it's when the content from the DB has quotes, that's when it value doesn't show everything.

here's my code

Code: Select all

PHP Code:
<select name="icons[]" size="10" multiple id="icons[]" 
        <option value=""></option> 
        <?php 
do {   
?> 
        <option value="<?php $value = stripslashes($value); echo $value?>"><?php echo $row_icons['icon']?></option> 
        <?php 
} while ($row_icons = mysql_fetch_assoc($icons)); 
  $rows = mysql_num_rows($icons); 
  if($rows > 0) { 
      mysql_data_seek($icons, 0); 
      $row_icons = mysql_fetch_assoc($icons); 
  } 
?> 

      </select>

Now i'm pretty sure i can change the stripslashes to something else, but i don't what will make it work...i've tried addslashes, and htmlentities....

Thank you

Posted: Fri Oct 29, 2004 2:26 am
by Tubbietoeter
try str_replace ... find details on php.net

Posted: Fri Oct 29, 2004 3:25 am
by Christopher
It is hard to tell from your code because it does not show where $value is assigned. I would think you would use addslashes() to put it between quotes.

Posted: Fri Oct 29, 2004 9:37 am
by grudz
ok....an example of the $value in my DB is this:

<a href="images/popup_5a7.png" onclick="popImg(this.href); return false;"><img src="images/legend_5a7.gif" border="0" alt="5 a 7"></a>

would that help?

Posted: Fri Oct 29, 2004 12:45 pm
by rehfeld
its not valid html to put html inside of a select or option element, just cant do that

you could do this though:

Code: Select all

$value = htmlspecialchars($value);
<option value="<?php echo $value; ?>"><?php echo $value; ?></option>