Search code examples
phpsyntax-errordropdownbox

Can Not Populate Dropdown When Placing Elements In Table


I am using php to connect to MS SQL and populate some dropdowns on their own everything works as expected. Its when I attempt to put the elements in a table that I am getting an error at "' . $row['RCC'] .'"; I keep getting a syntax error. Can anyone assist on what I am missing because I am new to PHP that I am lost here, thanks in advance

echo '
<table>
  <tr>
    <td>Select Region:</td>
    <td>
    <select name=RCC>;
     <option value='" . $row['RCC'] . "'>"' . $row['RCC'] .'"</option>;
    </select>
    </td>
  </tr>
</table>';

Solution

  • You should use "" and ' correctly to escape from php stuffs in your string

    echo '
    <table>
      <tr>
        <td>Select Region:</td>
        <td>
        <select name=RCC>;
         <option value="' . $row['RCC'] . '">"' . $row['RCC'] .'"</option>;
        </select>
        </td>
      </tr>
    </table>';