我遇到了使用標記中的value屬性將存儲在PHP變量中的數據輸入到HTML表單中的問題。問題似乎是字符串正在圍繞空格切割,其中只有字符串的第一部分在空格形成表單之前。沒有空格的字符串在最後以正斜槓出現。將PHP變量轉換爲HTML表單字段的問題
表單的想法是客戶可以在MySQL數據庫上編輯關於它們的詳細信息存儲,然後使用更新語句更改值。因此,值存儲在PHP變量中時顯示值非常重要。
例子:
<?php
//session start//
session_start();
//Connect to the server and database//
$con=mysqli_connect("127.0.0.1","root","","mia");
//Generate the sql statement for retrieval of customer details//
$customerdetails="SELECT Name, BusinessName, Address, Postcode, TelNo, Email
FROM customer
WHERE CustomerID = " . $_SESSION['CustomerID'] . "";
//execute the 'Customer details retrieve' sql statement//
$result= mysqli_query($con, $customerdetails);
while ($row = mysqli_fetch_array($result))
{
$Name='' . $row['Name'] . '';
$BusinessName=$row['BusinessName'];
$Addresss=$row['Address'];
$Postcode=$row['Postcode'];
$TelNo=$row['TelNo'];
$Email=$row['Email'];
}
//Write the web page//
echo "<!Doctype html>
<html>
<head>
<title>
Edit Details
</title>
</head>
<body>
<h1>Edit Details</h1>
<p>Please change values below where apropriate</p>
<form name='input'
action='../php/update_customer.php'
method='post'>
Name: <input type='string'
name='Name' value=" . $Name ."/> </br>
Business Name: <input type='text'
name='BusinessName' value=" . $BusinessName ."/> </br>
Address: <input type='text'
name='Address' value=" . $Addresss ."/> </br>
Post Code: <input type='text'
name='Postcode' value=" . $Postcode ."/> </br>
Telephone No: <input type='text'
name='TelNo' value=" . $TelNo ."/> </br>
Email Address: <input type='text'
name='Email' value=" . $Email ."/> </br>
<input type='submit' value='Update'/>
</form>
<p>" . $Name . "</p>
<p>" . $_SESSION['CustomerID'] . "</p>
</body>
</html>";
?>
你的意思是除了HTML注入問題嗎?考慮'Bob'的名稱值>