Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I populate the selected value of drop down lists with Mysql data?
    text
    copied!<p>I need the values of form inputs to be populated by the sql database. My code works great for all text and textarea inputs but I can't figure out how to assign the database value to the drop down lists eg. 'Type of property' below. It revolves around getting the 'option selected' to represent the value held in the database.</p> <p>Here is my code:</p> <pre><code>$result = $db-&gt;sql_query("SELECT * FROM ".$prefix."_users WHERE userid='$userid'"); $row = $db-&gt;sql_fetchrow($result); echo "&lt;center&gt;&lt;font class=\"title\"&gt;"._CHANGE_MY_INFORMATION."&lt;/font&gt;&lt;/center&gt;&lt;br&gt;\n"; echo "&lt;center&gt;".All." ".fields." ".must." ".be." ".filled." &lt;form name=\"EditMyInfoForm\" method=\"POST\" action=\"users.php\" enctype=\"multipart/form-data\"&gt; &lt;table align=\"center\" border=\"0\" width=\"720\" id=\"table1\" cellpadding=\"2\" bordercolor=\"#C0C0C0\"&gt; &lt;tr&gt; &lt;td align=\"right\"&gt;".Telephone." :&lt;/td&gt; &lt;td&gt; &lt;input type=\"text\" name=\"telephone\" size=\"27\" value=\"$row[telephone]\"&gt; Inc. dialing codes &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td align=\"right\"&gt;".Type." ".of." ".property." ".required." :&lt;/td&gt; &lt;td&gt;Select from list: &lt;select name=\"req_type\" value=\"$row[req_type]\"&gt; &lt;option&gt;House&lt;/option&gt; &lt;option&gt;Bungalow&lt;/option&gt; &lt;option&gt;Flat/Apartment&lt;/option&gt; &lt;option&gt;Studio&lt;/option&gt; &lt;option&gt;Villa&lt;/option&gt; &lt;option&gt;Any&lt;/option&gt; &lt;/select&gt; &lt;/td&gt; &lt;/tr&gt; .... </code></pre>
 

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