I have created a series of web pages one creates users into a sql database another page looks up all of these users then needs to show them in a drop down list for another database input. On calling the php file and using echo to print out the array it works fine however when i put it within my html file the drop down menu simply displays "$username_array[] = "\"".$row['Username'].""\" once I believe its something to do with escaping quotes however cant figure it out any help would be greatly appreciated!!
This is the code held within the html file
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$db = 'fid';
echo "<label class=\"input\" for=\"investigator\" type=\"input\">Investigator:<select id=\"investigator\" name=\"investigator\">";
$conn = mysql_connect($dbhost,$dbuser,$dbpass);
if (!$conn)
die('Could not connect: ' . mysql_error());
mysql_select_db($db);
$username_array = array();
$sql = mysql_query("SELECT `Username` FROM `user`");
while ($row = mysql_fetch_array($sql)){
//echo $username_array[] = "\"".$row['Username']."\"";
echo "<option value='null'>"$username_array[] = "\"".$row['Username'].""\"</option>";
}
echo "</label>";
mysql_close($conn)
?>
I want the username array to display one user after the other within a drop down list however currently just echos out the option value line without any interpretation
UPDATE
I've now changed the code to this
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$db = 'fid';
$conn = mysql_connect($dbhost,$dbuser,$dbpass);
if (!$conn)
die('Could not connect: ' . mysql_error());
mysql_select_db($db);
echo '<select id="investigator" name="investigator">';
$resource = mysql_query("SELECT `Username` FROM `user`");
if($resource && mysql_num_rows($resource)) {
while ($row = mysql_fetch_assoc($resource)){
echo '<option value="'.$row['Username'].'">'.$row['Username'].'</option>';
}
}
echo '</select>';
mysql_close($conn)
?>
however the html outputs the script rather than a drop down list and the usernames
html output
'; $resource = mysql_query("SELECT Username FROM user"); if($resource && mysql_num_rows($resource)) { while ($row = mysql_fetch_assoc($resource)){ echo ''; } } echo ''; mysql_close($conn) ?>
any help would be appeciated I just really need to get this working as its been bugging me for days!