我在使用标记中的 value 属性将存储在 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>";
?>