So here's my problem. I have a table on a database name 'countries'. It has two columns: 'countries' and 'id'. I am trying to take the data from this table and put it into a drop box for a registration form. Here's what I have (streamlined for your convenience):
$dbase_connection = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
<form method="post" action="register.php" name="registerform">
<select id="country_list">
<script type="text/javascript">
var select = document.getElementById("country_list");
<?php
while($row = $dbase_connection->query("SELECT * FROM countries")->fetch_array()){
?>
var option = document.createElement("option");
option.textContent = <?php $row['country_name']; ?>;
option.value = <?php $row['id']; ?>;
select.appendChild(option);
<?php
}
?>
</script>
</select>
</form>
No error is returned. The script gets as far as trying to load the drop box in the browser and pretty much cuts off right there. So i am left with an empty drop box, and none of the elements preceding it, which should be displayed (submit button etc) are loaded.
In my amateurish observation, it looks pretty messy, and i have been stumped on this for a few hours. First question for me on this website, let me know what other info i need to add.
<option>
tags? You can just use PHP to print the tags and add in the info from your PHP variables, as in the answers below. – HttpNinja 48 mins ago