-2

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.

jack
  • 155
  • 5
  • 14
  • _had no success_: what happened? What did you expect? What did you try but didn't work? – Hans Lub Dec 27 '14 at 12:27
  • apologies, my mistake ... I found these lines n the w3school.com website and tried them on the online compiler of the site and was ok. now i am trying to add them to my code, these lines to populate a drop down menu. – jack Dec 29 '14 at 15:47
  • _More information about this error may be available in the server error log_ : did you have a look there? Hint: have a look at the colour of the "a", "b" in the code block above. It tells you that you may have to [escape some quotes](http://stackoverflow.com/questions/7999148/escaping-quotation-marks-in-php).... – Hans Lub Dec 29 '14 at 16:28

1 Answers1

2

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 ...
?>
Todd
  • 5,314
  • 3
  • 28
  • 45
  • Looks like the correct answer. But not very useful: please make your correction more visible and explain _why_ the original didn't work. – Hans Lub Dec 27 '14 at 12:45
  • where's your answer, bro? – Todd Dec 27 '14 at 12:45
  • You also added the (needed) `name` attribute! Anyway, much better already! – Hans Lub Dec 27 '14 at 12:51
  • you write it your own: just copy and paste. does not qualify as an answer. btw. there is no question. and these PHP comments in HTML don't work that well - just those mistakes that happen with copy and pasting I guess. – hakre Dec 27 '14 at 14:16
  • Todd, i tried this but it's not working. gives me the internal server error. – jack Dec 29 '14 at 15:50