将数据库结果输出到文本框

When I connect to my database and try to output it's result in to a text box, it wouldn't print anything that would comes after a space. For example, as shown in the image bellow, it only prints out Brown and wouldn't show the rest. (This only happens if there is a space). However, this problem doesn't happen if I print the result without using a text box. Please let me know if there is anything I can do make it work with a textbox.

<?php

$connInfo = array(
        'Database' => 'database_name',
        'UID' => 'user_ID',
        'PWD' => 'my_password',
        'ReturnDatesAsStrings' => true 
        );

    $connectString = sqlsrv_connect('sever_name.com', $connInfo) or die("Can't connect to the database.");


$query_infor = "SELECT * FROM ElectronicShop WHERE WorkOrder=5";
$data_infor = sqlsrv_query($connectString, $query_infor) or die(print_r(sqlsrv_errors(SQLSRV_ERR_ALL), true));
$row_infor = sqlsrv_fetch_array($data_infor);

echo "Printing the name outside the textbox: ".$row_infor['fullname']."<br><br>";
echo "Should show both LastName and FirstName: <input id=\"fullname\" type=\"text\" name=\"fullname\" value=".$row_infor['fullname']." >";

?>

enter image description here

1个回答

This is because you don't have the value attribute in quotes. Your HTML looks like this: value=Brown Sam as opposed to value="Brown Sam".

You should use something like this:

echo 'Should show both LastName and FirstName: <input id="fullname" type="text" name="fullname" value="'.$row_infor['fullname'].'" >';
duaabhuv188411
duaabhuv188411 感谢您通过示例向我展示。 它帮助了很多
大约 6 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐