while ($row = $result->fetch_assoc()) {
echo "<option name="{$row["pagename']}>{echo $row['pagename']}</option>";
to
<?php
while ($row = $result->fetch_assoc()) {
?>
<option name="<?php echo $row['pagename']; ?>" > <?php echo $row['pagename']; ?> </option>
<?php
} ?>
solved How To print out some data from a select query using PHP [closed]