title: echo MySQL data into html form with radio buttons with other text field
body: <p>In my web form, users can submit product data into a MySQL database. The supplier field gives our users the choice between 3 radio buttons (our most frequently used suppliers being Sigma-Aldrich, VWR and Filter-Service), or a 4th 'other' radio button with a text field, where they can specify the 'other' supplier. This is done using the following code:</p>
  
  <p>php side:</p>
  
  <pre><code>if (isset($_POST['submit'])) {
  $q2_productname = $conn-&gt;real_escape_string($_POST['q2_productname']);
  $q3_supplier = $conn-&gt;real_escape_string($_POST['q3_supplier']);
  if ($q3_supplier =='other'){
    $q3_supplier = $conn-&gt;real_escape_string($_POST['q3_supplier_other']);
  }
  </code></pre>
  
  <p>and the form on the html side:</p>
  
  <pre><code>&lt;fieldset&gt;
  &lt;div&gt;
  &lt;label for="q2"&gt;&lt;font color="red"&gt;*&lt;/font&gt; Full product name:&lt;/label&gt;&lt;br /&gt;
  &lt;input id="q2" type="text" style="width:400px" name="q2_productname" required="true" tabindex="2"&gt;
  &lt;/div&gt;
  &lt;/fieldset&gt;
  &lt;fieldset&gt;
  &lt;div&gt;
  &lt;label for="q3"&gt;&lt;font color="red"&gt;*&lt;/font&gt; Supplier:&lt;/label&gt;&lt;br /&gt;
  &lt;input id="q3" type="radio" name="q3_supplier" required="true" tabindex="3" value="Sigma-Aldrich" onchange="disableTxt()" checked="checked" /&gt;Sigma-Aldrich &amp;nbsp;
  &lt;input id="q3" type="radio" name="q3_supplier" required="true" tabindex="3" value="VWR" onchange="disableTxt()" /&gt;VWR &amp;nbsp;
  &lt;input id="q3" type="radio" name="q3_supplier" required="true" tabindex="3" value="Filter-Service" onchange="disableTxt()" /&gt;Filter-Service &amp;nbsp;
  &lt;input id="q3" type="radio" name="q3_supplier" required="true" tabindex="3" value="other" onchange="enableTxt()" /&gt;Other:
  &lt;input id="other" type="text" name="q3_supplier_other" required="true" tabindex="3" disabled="disabled" /&gt;
  &lt;script&gt;
  function disableTxt() {
      document.getElementById("other").disabled = true;
  }
  function enableTxt() {
      document.getElementById("other").disabled = false;
  }
  &lt;/script&gt;
  &lt;/div&gt;
  &lt;/fieldset&gt;
  </code></pre>
  
  <p>Now, I also have an edit page, where users can edit and update an entry.
  For the normal text fields I've managed to echo the value into the text fields. <strong>For the supplier I'd like to echo the value into the same layout as the webform (i.e. check the corresponding radio button and if it's 'other' then check the 'other' radio button and fill in the 'other' text field)</strong>, but this seems to be rather difficult.</p>
  
  <p>I'm trying </p>
  
  <pre><code>&lt;input id="q3" type="radio" name="ud_q3_supplier" required="true" tabindex="3" value="other" onchange="enableTxt()" &lt;?php if (isset($q3_supplier) &amp;&amp; $q3_supplier!="Sigma-Aldrich" OR "VWR" OR "Filter-Service") echo "checked";?&gt; /&gt;Other:
  </code></pre>
  
  <p>to get the other radio button checked in case it's different to one of the 3 frequently used suppliers, and then I also put at the text field</p>
  
  <pre><code>&lt;input id="other" type="text" name="ud_q3_supplier_other" required="true" tabindex="3" disabled="disabled" value="&lt;?php if (isset($q3_supplier) &amp;&amp; $q3_supplier!="Sigma-Aldrich" OR "VWR" OR "Filter-Service") echo $q3_supplier;?&gt;" /&gt;
  </code></pre>
  
  <p>but the result is that the code always selects the other text field and fills in the value in the text field anyway, regardless of it being something different from Sigma-Aldrich, VWR or Filter-Service...</p>
  
  <p>I'm thinking <strong>the OR statements are not working correctly</strong>, but my google and stackoverflow searches haven't resulted in solutions neither examples. Does anyone have tips to crack this issue?</p>
  
  <p>The code for the editing form php side:</p>
  
  <pre><code>$sid = (int)$_GET['sid'];
  $sql = "SELECT * FROM orders WHERE sid = '$sid'";
  $result = $conn-&gt;query($sql);
  
  if ($result-&gt;num_rows &gt; 0) {
      while($row = $result-&gt;fetch_array(MYSQLI_ASSOC)) {
          $sid = $row['sid'];
          $q2_productname = $row['q2_productname'];
          $q3_supplier = $row['q3_supplier'];
      }
  }
  </code></pre>
  
  <p>and html side:</p>
  
  <pre><code>&lt;input type="hidden" name="sid" value="&lt;?=$sid;?&gt;"&gt;&lt;br&gt;
  &lt;font color="red"&gt;*&lt;/font&gt; Product name: &lt;input id="q2" type="text" style="width:400px" name="ud_q2_productname" required="true" value="&lt;?=$q2_productname?&gt;" tabindex="2"&gt;&lt;br&gt;
  &lt;font color="red"&gt;*&lt;/font&gt; Supplier: 
  &lt;input id="q3" type="radio" name="ud_q3_supplier" required="true" tabindex="3" value="Sigma-Aldrich" onchange="disableTxt()" &lt;?php if (isset($q3_supplier) &amp;&amp; $q3_supplier=="Sigma-Aldrich") echo "checked";?&gt; /&gt;Sigma-Aldrich &amp;nbsp;
  &lt;input id="q3" type="radio" name="ud_q3_supplier" required="true" tabindex="3" value="VWR" onchange="disableTxt()" &lt;?php if (isset($q3_supplier) &amp;&amp; $q3_supplier=="VWR") echo "checked";?&gt; /&gt;VWR &amp;nbsp;
  &lt;input id="q3" type="radio" name="ud_q3_supplier" required="true" tabindex="3" value="Filter-Service" onchange="disableTxt()" &lt;?php if (isset($q3_supplier) &amp;&amp; $q3_supplier=="Filter-Service") echo "checked";?&gt; /&gt;Filter-Service &amp;nbsp;
  &lt;input id="q3" type="radio" name="ud_q3_supplier" required="true" tabindex="3" value="other" onchange="enableTxt()" &lt;?php if (isset($q3_supplier) &amp;&amp; $q3_supplier!="Sigma-Aldrich" OR "VWR" OR "Filter-Service") echo "checked";?&gt; /&gt;Other:
  &lt;input id="other" type="text" name="ud_q3_supplier_other" required="true" tabindex="3" disabled="disabled" value="&lt;?php if (isset($q3_supplier) &amp;&amp; $q3_supplier!="Sigma-Aldrich" OR "VWR" OR "Filter-Service") echo $q3_supplier;?&gt;" /&gt;&lt;br /&gt;
  &lt;script&gt;
  function disableTxt() {
      document.getElementById("other").disabled = true;
  }
  function enableTxt() {
      document.getElementById("other").disabled = false;
  }
  &lt;/script&gt;
  </code></pre>