我是PHP的新手,我正在尝试创建一个将从MySQL数据库自动填充的表单。表单将被创建,并从数据库数据中填充。 但是,如果数据中间包含空格,则不会显示空格后的字符。
php页面:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
// Check if we have parameters employeeId being passed to the script through the URL
if (isset($_GET["employeeId"])) {
$employeeId = $_GET["employeeId"];
//=============Data Display=================
$con=mysqli_connect("localhost","root","","employee_db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT `employee_id` , `employee_name` , `employee_email` , `employee_mobile` , `employee_address`
FROM `employee_details`
WHERE `employee_id` =$employeeId");
echo "<h2>Edit Employee</h2><br/>
<form name='myForm' action='' onSubmit='return validateForm()' method='post'>";
while($row = mysqli_fetch_array($result))
{
echo "Employee Id: ". $row['employee_id'] ."<br/>";
echo "Employee Name: <input type='text' name='EmployeeName' value=". $row['employee_name'] ."><br/>";
echo "Employee Email: <input type='text' name='EmployeeEmail' value=". $row['employee_email'] ."><br/>";
echo "Employee Mobile: <input type='text' name='EmployeeMobile' value=". $row['employee_mobile'] ."><br/>";
echo "Employee Address: <Input type='text' name = 'product_name5' value=".$row['employee_address']."><br/>";
}
mysqli_close($con);
//=============Data Display=================
}
?>
</body>
</html>
我哪里错了?我该怎么做才能获得所有数据,包括文本框中的空格?
答案 0 :(得分:3)
Value
属性也应该带引号:
value='" . $value . "'
在你的情况下:
echo "Employee Name: <input type='text' name='EmployeeName' value='". $row['employee_name'] ."'><br/>";
echo "Employee Email: <input type='text' name='EmployeeEmail' value='". $row['employee_email'] ."'><br/>";
echo "Employee Mobile: <input type='text' name='EmployeeMobile' value='". $row['employee_mobile'] ."'><br/>";
echo "Employee Address: <Input type='text' name = 'product_name5' value='".$row['employee_address']."'><br/>";
答案 1 :(得分:0)
如果您要从数据库创建链接提取,例如下载链接 使用此类型代码
$result = mysqli_query($con,$sql);
//echo $ip."<br />";REGEXP
//echo $name."<br />";
echo "<table border=2px style='border-radius=20px;' align=center><tr>
<th>Document ID</th>
<th>Document Name Type</th>
<th>Download Documents</th>
</tr>";//<th>Project Document Type</th>
while($row = mysqli_fetch_array($result)) {
$path1=$row['FOLDERNAME'] .'/'. $row['FILENAME'] .'.'. $row['DOCTYPE'];
$path=str_replace(" ", '%20', $path1);
echo "<tr>";
echo "<td>" . $row['DocID'] . "</td>";
// echo "<td>" . $row['PROJDOCTYPE'] . "</td>";Thank you. Your Apple ID is now ready for use.
echo "<td>" . $row['DOCNAME'] . "</td>";
echo '<td><a href=Tender/'.$path.'>'.$row['DOCNAME'].'</a></td>';
echo "</tr>";
}
echo "</table>";
mysqli_close($con);