douqianbiao4216 2014-12-27 12:22
浏览 15
已采纳

填充php表中的DropDown列表

In the php Code, the following code is used to build a table with format and all 3 cells for text and one cell for image upload.

 echo "<table border=1 align=center>
                                   <tr bgcolor='#FFC600'>
                                   <th>sectionID</th>
                                   <th>name</th>
                                   <th>price</th>
                                   <th>image</th>
                                   <th>add</th>
                                   </tr>";
                                   echo "<form action=Data.php enctype=multipart/form-data method=post>";
                                   echo "<tr>";
                                   // give the insert row a special color
                                   echo "<tr bgcolor='#FFC600'>";
                                   echo "<td><input type=text name=cat_id></td>";
                                   echo "<td><input type=text name=item_name></td>";
                                   echo "<td><input type=text name=item_price></td>";
                                   echo "<td><input type=file name=uploaded_file></td>";
                                   echo "<td>" . "<input type=submit name=add value=addNew" . " </td>";
                                   echo "</tr>";
                                   echo "</form>";
                                   echo "</table>";
                                   echo "<br>";

I need to change the input for cat_id to a dropdownlist, i tried to implement this code but had no success.

<select>
  <option value="a">aa</option>
  <option value="b">bb</option>
  <option value="c">cc</option>
  <option value="d">dd</option>
</select>

This is what i tried so far: adding the 6 above lines to the code as follows:

echo "<form action=myItemsData.php enctype=multipart/form-data method=post>";
                                   echo "<tr>";
                                   // give the insert row a special color
                                   echo "<tr bgcolor='#FFC600'>";
                                   echo "<td>
                                   <select name=cat_id>
                                   <option value="a">aa</option>
                                   <option value="b">bb</option>
                                   <option value="c">cc</option>
                                   <option value="d">dd</option>
                                   </select>
                                   </td>";
                                   echo "<td><input type=text name=item_name></td>";
                                   echo "<td><input type=text name=item_price></td>";
                                   echo "<td><input type=file name=uploaded_file></td>";
                                   echo "<td>" . "<input type=submit name=add value=addNew" . " </td>";
                                   echo "</tr>";
                                   echo "</form>";
                                   echo "</table>";
                                   echo "<br>";

and i got this back when i tried to load the page on the browser:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

  • 写回答

1条回答 默认 最新

  • dongluanguang4774 2014-12-27 12:38
    关注

    so, I simplified things by using a HEREDOC, which is great for long, multi-line strings. the only thing else really needed was a simple cut and paste of the select into the cell where the input was.

    echo <<<EOT
    <table border=1 align=center>
      <tr bgcolor='#FFC600'>
        <th>sectionID</th>
        <th>name</th><th>price</th>
        <th>image</th>
        <th>add</th>
      </tr>
      <form action=Data.php enctype=multipart/form-data method=post>
      <tr>;
      // give the insert row a special color
      <tr bgcolor='#FFC600'>
        <td>
          <select name=cat_id>
            <option value="a">aa</option>
            <option value="b">bb</option>
            <option value="c">cc</option>
            <option value="d">dd</option>
          </select>
        </td>
        <td><input type=text name=item_name></td>
        <td><input type=text name=item_price></td>
        <td><input type=file name=uploaded_file></td>
        <td><input type=submit name=add value=addNew> </td>
      </tr>
      </form>
    </table>
    <br>
    EOT;
    

    EDIT:

    unless you must have this html in string form for some reason (i.e. you're just rendering the HTML), why not just do this?

    if you need to insert variables into the markup, then just put vars in php tags:

    <keygen><?php echo $myVariable ?></keygen>
    

    try this:

    <?php
        ... some preceding php here ...
    ?>
    
    <table border=1 align=center>
      <tr bgcolor='#FFC600'>
        <th>sectionID</th>
        <th>name</th><th>price</th>
        <th>image</th>
        <th>add</th>
      </tr>
      <form action=Data.php enctype=multipart/form-data method=post>
      <tr>;
      // give the insert row a special color
      <tr bgcolor='#FFC600'>
        <td>
          <select name=cat_id>
            <option value="a">aa</option>
            <option value="b">bb</option>
            <option value="c">cc</option>
            <option value="d">dd</option>
          </select>
        </td>
        <td><input type=text name=item_name></td>
        <td><input type=text name=item_price></td>
        <td><input type=file name=uploaded_file></td>
        <td><input type=submit name=add value=addNew> </td>
      </tr>
      </form>
    </table>
    <br>
    
    <?php
        ... some following php here ...
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog