Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm still unclear on what exactly you're trying to accomplish. Your current code is only saving the last <code>'color-name'</code> and <code>'shape'</code> objects being read in from the file. It then can configure the <code>selected</code> option by making this change:</p> <pre><code>&lt;option value="red" &lt;?php if($color_name == 'red'){?&gt;selected="selected"&lt;?php }?&gt;&gt;Red&lt;/option&gt;; &lt;option value="blue" &lt;?php if($color_name == 'blue'){?&gt;selected="selected"&lt;?php }?&gt;&gt;Blue&lt;/option&gt;; &lt;option value="green" &lt;?php if($color_name == 'green'){?&gt;selected="selected"&lt;?php }?&gt;&gt;Green&lt;/option&gt;; &lt;option value="purple" &lt;?php if($color_name == 'purple'){?&gt;selected="selected"&lt;?php }?&gt;&gt;Purple&lt;/option&gt;; </code></pre> <p>NOTE: The way you're reading in the file appends carriage returns/line returns at the end of your variables...for example, <code>$color_name</code> on my end contains two extra hex values at the end of the string: <code>x0d</code> and <code>x0a</code></p> <p>EDIT #2: Try making your form like this:</p> <pre><code>&lt;form method="post" action="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;"&gt; &lt;select id="color_choice"&gt; &lt;option id="round"&gt;Round&lt;/option&gt; &lt;option id="square"&gt;Square&lt;/option&gt; &lt;/select&gt; &lt;input type="submit" name="Submit" value="Submit" /&gt; &lt;/form&gt; &lt;script&gt; var option = document.getElementById("color_choice"); option.options['&lt;?php echo $shape ?&gt;'].selected = true; &lt;/script&gt; </code></pre> <p>I'm pretty sure this will work, changes I made were: <br /> 1) Using javascript instead of php to change selected <br /> 2) Using <code>id</code> attributes instead of <code>value</code> or <code>name</code> <br /> 3) Added <code>&lt;script&gt;</code> tag at the end of form (it may not work if it's before)<br /></p> <p>You'll have to make changes to the form and the script depending on what type of values you're pulling from the file...but you should be able to figure out how to handle that.</p>
    singulars
    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.
    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