Re: can't output sql query with php code.

From: Date: Mon, 06 Feb 2006 07:15:27 +0000
Subject: Re: can't output sql query with php code.
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-229918@lists.php.net to get a copy of this message
Hi Paul, If "equip" contains a space it will probably break the dropdown. Change it to: echo "<option value='" . htmlspecialchars($val) . "'>$val</option>\n"; in case it has quotes, spaces, < or > in it. Paul Goepfert wrote:
Hi all, I have a mysql database setup to use with my php web page. I have been able to access the database and get values into my drop down menus. However when I tried to output the contents into two two diferent variables the code does not work. To be more specific I will show you the code both the one that works and the one that doesn't Doesn't work ------------------------------------------------- <?php $month_query = mysql_query("SELECT m_id, months FROM Month"); while ($row = mysql_fetch_array($month_query)) {
     $val = $row["m_id"];
     $out = $row["months"];
     echo "<option value=$val>$out</option>";
} ?> --------------------------------------------- Code that works --------------------------------------------- <?php echo ' <select name="equipment" size="1" id="equip" onChange="addRow()">'; $Equip_query = mysql_query("SELECT equip FROM Equipment ORDER BY equip ASC"); while ($r = mysql_fetch_array($Equip_query)) { $val = $r["equip"]; echo "<option value=$val>$val</option>\n"; } echo "</select></td>"; ?> Also I should tell you that the code that works comes after the code that doesn't work in my web page. Oh for the values that are outputted in the code that doesn't work are val is numeric and out is a string. I know my sql query works because I tested it in mysql. Thanks for the help Paul


« previous php.general (#229918) next »