0

So my PHP displays a MySQL table, I'm aware you can tyle these which I plan to. But as the image below shows, the add button adds another column. enter image description here

Is it possible to make the add button below the two columns update and delete? If so how can I do this. Here is my code, sorry for any errors or being messy, I'm still learning.

while ($record = mysql_fetch_array($myData)) {
  echo "<form action=usermanagement.php method=post>";
  echo "<tr>";
  echo "<td>" . "<input type=text name=id value=" . $record['ID'] . " </td>";
  echo "<td>" . "<input type=text name=rank value=" . $record['Rank'] . " </td>";
  echo "<td>" . "<input type=text name=username value=" . $record['Username'] . " </td>";
  echo "<td>" . "<input type=text name=password value=" . $record['Password'] . " </td>";
  echo "<td>" . "<input type=hidden name=hidden value=" . $record['ID'] . " </td>";
  echo "<td>" . "<input type=submit name=update value=update" . " </td>";
  echo "<td>" . "<input type=submit name=delete value=delete" . " </td>";
  echo "</tr>";
  echo "</form>";
}
echo "<form action=usermanagement.php method=post>";
echo "<tr>";
echo "<td><input type=text name=uid></td>";
echo "<td><input type=text name=urank></td>";
echo "<td><input type=text name=uusername></td>";
echo "<td><input type=text name=upassword></td>";
echo "<td>" . "<input type=submit name=add value=add" . " </td>";
echo "</form>";
echo "</table>";    
1
  • btw, you never closed off <input type=submit name=add value=add and you really should quote your input attributes as will many of your other inputs which will fail you. Commented Feb 5, 2016 at 14:43

3 Answers 3

1

Pay attention to the closing tags of the inputs.. the hidden inputs can be put anywhere in the table as they not being displayed:

while($record = mysql_fetch_array($myData)) {
    echo '<form action=usermanagement.php method=post>
              <tr>
                   <td>
                        <input type=text name=id value="' . $record['ID'] . '" />
                   </td>
                   <td>
                        <input type=text name=rank value="' . $record['Rank'] . '" />
                   </td>
                   <td>
                        <input type=text name=username value="' . $record['Username'] . '" />
                   </td>
                   <td>
                        <input type=text name=password value="' . $record['Password'] . '" />
                   </td>
                   <td>
                        <input type=hidden name=hidden value="' . $record['ID'] . '" />
                        <input type=submit name=update value=update />
                   </td>
                   <td>
                        <input type=submit name=delete value=delete />
                   </td>
              </tr>
          </form>';
}

echo '<form action=usermanagement.php method=post>
          <tr>
               <td>
                    <input type=text name=uid />
               </td>
               <td>
                    <input type=text name=urank />
               </td>
               <td>
                    <input type=text name=uusername />
               </td>
               <td>
                    <input type=text name=upassword />
               </td>
               <td colspan="2">
                    <input type=submit name=add value=add />
               </td>
          </tr>
      </form>';

Also, try stop using mysql_* functions as they being deprecated. Use PDO, mysqli_ or the MySQLi class instead.

Sign up to request clarification or add additional context in comments.

Comments

0

Use css (add class="add" to the add button):

 .add{
   position: relative;
   left: 50px; (...adjust)
 }

Comments

0

You should replace this:

echo "<td>" . "<input type=submit name=add value=add" . " </td>";

By this:

echo "<td colspan='3'>" . "<input type=submit name=add value=add" . "></td>";

4 Comments

Partly, yes. However this will throw a parse error for a few reasons.
Also there is no need to wrap hidden field in <td>'s, so it will looks like:echo "<input type=hidden name=hidden value=" . $record['ID'];
many of their other inputs are missing the closing >. so, you may have to rework their code. I've placed a comment under their question about it.
<td colspan="3"> that will cause a parse error and should either be single quotes, or to escape them <td colspan=\"3\">. Because the echo is set in double quotes. Edit: <input type=submit name=add value=add should be <input type=submit name=add value=add> but they really should be quoting those too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.