开发者

PHP array string element

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='lis开发者_开发问答tid' 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,


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>";
}
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜