我是php的新手。我在mysql中创建了一个客户端数据库,现在我希望通过Web浏览器进行编辑,因此我创建了一个非常基本的Web应用程序。
我希望以文本字段的形式查看客户列表,旁边有一个编辑按钮。我想在php中创建一个html表单,但它似乎不起作用。有人可以帮帮我吗。代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Price List</title>
<style type="text/css">
h1 {text-align: center;}
h1 {font-family: "Times New Roman";}
h1 {color: #060;}
p {text-align: justify;}
p {font-family: "Times New Roman";}
p {font-size: 16px;}
table {border-color: #060}
table {border-style: double;}
</style>
</head>
<body background="background/lgrey_background.gif">
<center>
<table border="2" width="750">
<tr>
<td colspan="2">
<img src = "upper_banner/upper_banner.jpg" alt ="Upper Banner"/>
</td>
</tr>
<tr>
<td colspan="2">
</td>
</tr>
<tr>
<td colspan="2">
<h1>Clients List</h1>
<p>
The following is the clients list:
</p>
<center>
<table border="1">
<tr>
<td><strong>ID</strong></td><td><strong>Name</strong></td><td><strong>Surname</strong></td>
</tr>
<?php
$connect = mysqli_connect("localhost","admin", "XXX", "clients db");
if ($connect->connect_error) {
die("Connection failed: " . $connect->connect_error);
}
$query = "SELECT id, name, surname FROM clients";
$executequery = $connect->query($query);
if ($executequery->num_rows > 0) {
while($row = $executequery->fetch_assoc()) {
echo'
<form method="post" action="update_clients_list.php">
<tr>
<td>
<input type="text" name="id" size="20" value="<?php echo "$row[id]"?>">
</td>
<td>
<input type="text" name="name" size="20" value="<?php echo "$row[name]"?>">
</td>
<td>
<input type="text" name="surname" size="20" value="<?php echo "$row[surname]"?>">
</td>
<td>
<input type="submit" name="submit value" value="Edit">
</td>
</tr>';
} else {
echo "0 results";
}
?>
</table>
</center>
</td>
</tr>
<tr>
<td>
<a href="site_map.php">Site Map</a>
</td>
<td>
</td>
</tr>
</table>
</center>
</body>
</html>
答案 0 :(得分:0)
Since you are new on PHP I would suggest you to review the usage of templates, like smarty or Blade, You will find how easy would result to achieve this type of projects.
For this specific project you will need to create a grid (table) then in front of each row add a simple form with a hidden values that will let you edit each client
Something like this
<table class="table">
<thead>
<tr>
<th>Row</th>
<th>First Name</th>
<th>Last Name</th>
<th>Email</th>
<th>Options</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>John</td>
<td>Carter</td>
<td>johncarter@mail.com</td>
<td>
<form method="post" action="edit-client.php" >
<input type="hidden" value="1" name="clientId" />
<button type="submit" value="Edit" />
</td>
</tr>
<tr>
<td>2</td>
<td>Peter</td>
<td>Parker</td>
<td>peterparker@mail.com</td>
<td>
<form method="post" action="edit-client.php" >
<input type="hidden" value="2" name="clientId" />
<button type="submit" value="Edit" />
</td>
</tr>
<tr>
<td>3</td>
<td>John</td>
<td>Rambo</td>
<td>johnrambo@mail.com</td>
<td>
<form method="post" action="edit-client.php" >
<input type="hidden" value="3" name="clientId" />
<button type="submit" value="Edit" />
</td>
</tr>
</tbody>
</table>
答案 1 :(得分:0)
如果我是你,我会首先将$ row []值放入变量中,然后在输入中添加它们就像这样。
<input type="text" value="' . $variable . '">