Note that there are some explanatory texts on larger screens.

plurals
  1. POUse HTML dropdownlist made in PHP with data from MySQL database
    primarykey
    data
    text
    <p>I have a PHP script which connects to a MySQL database and creates an HTML dropdown list with data retrieved from it. The script works, I just don't understand how I'm supposed to use it in an HTML form.</p> <p>The PHP script, named CountryList.php, looks like this:</p> <pre><code>&lt;?php function createCountryList() { $con = mysql_connect("localhost","user","pass"); mysql_select_db('database', $con); $sql="SELECT Country FROM CountryList"; $result = mysql_query($sql,$con); echo "&lt;select name=country value=''&gt;Country&lt;/option&gt;"; echo "&lt;option value=0&gt;Select Country&lt;/option&gt;"; echo "&lt;option value=1&gt;&lt;/option&gt;"; $curvalue=2; while($nt=mysql_fetch_array($result)){ echo "&lt;option value=$curvalue&gt;$nt[Country]&lt;/option&gt;"; $curvalue = $curvalue+1; } echo "&lt;/select&gt;"; mysql_close($con); } ?&gt; </code></pre> <p>I tried including the PHP file in the head of the HTML page with:</p> <pre><code>&lt;?php include("CountryList.php"); ?&gt; </code></pre> <p>And then I tried calling the function which creates the dropdown menu in a form later on:</p> <pre><code>&lt;form action="insert.php" method="POST"&gt; &lt;label&gt;Which country are you from?&lt;/label&gt; &lt;?php createCountryList(); ?&gt; &lt;/form&gt; </code></pre> <p>Since nothing happens, I did it wrong. Any advice? Help is appreciated.</p> <p>EDIT: Bah, I knew it was something silly. The page was an HTML file, PHP didn't process it. Changing the HTML file to PHP solved everything.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload