up vote 1 down vote favorite
share [fb]

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,

link|improve this question

1  
youre missing quote marks on your value attributes unless its just a type-o in your post... – prodigitalson Apr 9 at 0:06
feedback

1 Answer

up vote 1 down vote accepted

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>";
}
?>
link|improve this answer
any benefits to using htmlentities() over htmlspecialchars() ? – jnpcl Apr 9 at 0:35
htmlentities() is more thorough in its encoding of characters, however, either will do the trick. See here: stackoverflow.com/questions/46483/… – Andrew Yochum Apr 9 at 0:39
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.