First word only appearing in a form text box

2019-02-25 11:45发布

Yes, I am coding on New Year's eve. Anyway, I have what I think is a strange problem (strange enough to need help). The following code works (sort of). The echo on line 6 ($row["sitename"]) outputs a full name like "Huntington Park", BUT... the first textbox inside the form only shows "Huntington", not the second part of the name. Included below is a snipped of the screen.

    $query = "SELECT * FROM `siteinformation` 
            WHERE `id` = '".$sitedrop."'";
            echo $query;
    $results = $pdo->query($query);
        while ($row = $results->fetch()) { 
        echo $row["sitename"].'
            <form action="dummypage.php" method="post">
            <table width="526">
              <tr>
                <td width="520" align="right"><p>Site Name: 
                    <input type="text" name="sitename" value='.$row["sitename"].'>
                 </p>
                  <p>Program: 
                    <input type="text" name="program" value='.$row["program"].'>
                  </p>
                  <p>Phone: 
                    <input type="text" name="sitephone" value='.$row["sitephone"].'>
                  </p>
        </td>
        </tr>
        </table>
</form>';
        }

标签: php textbox
3条回答
Evening l夕情丶
2楼-- · 2019-02-25 12:06

Your code outputs:

<input type="text" name="sitename" value=Huntington Park>

and it should be:

<input type="text" name="sitename" value="Huntington Park">

Change:

    <input type="text" name="sitename" value='.$row["sitename"].'>

to:

    <input type="text" name="sitename" value="'.$row["sitename"].'">

Since the value is not in quotes - it picks only the first string! You should do the same with the other inputs.

查看更多
姐就是有狂的资本
3楼-- · 2019-02-25 12:14

Change:

<input type="text" name="sitename" value='.$row["sitename"].'>

to:

<input type="text" name="sitename" value="'.$row["sitename"].'">
查看更多
兄弟一词,经得起流年.
4楼-- · 2019-02-25 12:18

You may find that using HEREDOC notation is useful. http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

$results = $pdo->query($query);
$out = NULL;
while ($row = $results->fetch()) 
{ 
    $out. = <<<ENDOUT
    $row["sitename"]
    <form action="dummypage.php" method="post">
    <table width="526">
    <tr>
    <td width="520" align="right">
    <p>Site Name: 
    <input type="text" name="sitename" value="{$row["sitename"]}" />
    </p>
    <p>Program: 
    <input type="text" name="program" value="{$row["program"]}" />
    </p>
    <p>Phone: 
    <input type="text" name="sitephone" value="{$row["sitephone"]}" />
    </p>
    </td>
    </tr>
    </table>
    </form>
ENDOUT;
}
echo $out;
查看更多
登录 后发表回答