1

I have form:

<?php
while ($row = mysql_fetch_array($result)) {
  echo "<form action='login.php' method='POST'>";
  echo "<tr>";
  echo "<td align='center' valign='middle'><input type='text' name='listid' value=" . $row['g_id'] . " readonly size='15'></td>";
  echo "<td align='center' valign='middle'><input type='text' name='listid' value=" . $row['t1name'] . " readonly size='15'></td>";
  echo "<td align='center' valign='middle'><input type='text' name='listid' value=" . $row['t2name'] . " readonly size='15'></td>";
  echo "<td align='center' valign='middle'><input type ='submit' value ='Confirm game'></td>";
  echo "</form>";
  echo "</tr>";
}
?>

The code works fine except for 1 problem.

variables $row['t1name'] and row['t2name'] contain 3 words each. However the value of the field is assigned as the first word only. Nothing after 1st space is included.

if I do a print_r($row), I get:

Array
(
    [0] => 1
    [g_id] => 1
    [1] => 2011-03-22
    [date] => 2011-03-22
    [2] => 1
    [team1] => 1
    [3] => John Doe A
    [t1name] => John Doe A
    [4] => 9
    [t1pnts] => 9
    [5] => 2
    [team2] => 2
    [6] => JohnDoe B
    [t2name] => JohnDoe B
    [7] => 1
    [t2pnts] => 1
    [8] => 1
    [p1] => 1
    [9] => 3
    [p1p] => 3
    [10] => 3
    [p1w] => 3
    [11] => 2
    [p2] => 2
    [12] => 3
    [p2p] => 3
    [13] => 3
    [p2w] => 3
    [14] => 3
    [p3] => 3
    [15] => 3
    [p3p] => 3
    [16] => 3
    [p3w] => 3
    [17] => 6
    [p4] => 6
    [18] => 3
    [p4p] => 3
    [19] => 0
    [p4w] => 0
    [20] => 7
    [p5] => 7
    [21] => 3
    [p5p] => 3
    [22] => 0
    [p5w] => 0
    [23] => 8
    [p6] => 8
    [24] => 3
    [p6p] => 3
    [25] => 0
    [p6w] => 0
    [26] => 50
    [confirmed] => 50
)

Thank you,

1
  • 1
    youre missing quote marks on your value attributes unless its just a type-o in your post... Commented Apr 9, 2011 at 0:06

1 Answer 1

1

You're missing the quotes around your value. Also you should encode your output with htmlentities as well. See below:

<?php
while ($row = mysql_fetch_array($result)) {
  echo "<form action='login.php' method='POST'>";
  echo "<tr>";
  echo "<td align='center' valign='middle'><input type='text' name='listid' value='" . htmlentities($row['g_id']) . "' readonly size='15'></td>";
  echo "<td align='center' valign='middle'><input type='text' name='listid' value='" . htmlentities($row['t1name']) . "' readonly size='15'></td>";
  echo "<td align='center' valign='middle'><input type='text' name='listid' value='" . htmlentities($row['t2name']) . "' readonly size='15'></td>";
  echo "<td align='center' valign='middle'><input type ='submit' value ='Confirm game'></td>";
  echo "</form>";
  echo "</tr>";
}
?>
2
  • any benefits to using htmlentities() over htmlspecialchars() ? Commented Apr 9, 2011 at 0:35
  • htmlentities() is more thorough in its encoding of characters, however, either will do the trick. See here: stackoverflow.com/questions/46483/… Commented Apr 9, 2011 at 0:39

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.