我正在尝试创建一个管理页面,该页面将从表中提取行并允许“admin”进行更改。虽然我可以找出代码。我希望您建议我如何显示行数据并使其可编辑并可保存到数据库中。如果“管理员”只需要更新艺术家名称,我该如何管理,以保持其他数据不变。 我只是不知道如何完成这件事。
目前为止的更新页面:
<?php
//creating MySQL connection
$con=mysqli_connect('localhost','SouravBasuRoy','2525','MyteraArt');
//
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<link href="admin-styles.css" rel="stylesheet" type="text/css">
</head>
<body>
<h1>Admin Panel: Paintings | Mytera Art</h1>
<h2>Update a Painting</h2>
<hr>
<div>
<h1>Search by Painting Name :</h1>
<form name="SearchByPainting" action="editpainting.php" method="post">
<input list="paintings" name="frompaintings">
<datalist id="paintings">
<?php
//Insert Query to extract Artist names form Database
$result = mysqli_query($con,'SELECT `ArtName` FROM Paintings');
while($row = mysqli_fetch_array($result))
{
echo '<option value="' . $row['ArtName'] . '">' ;
}
?>
</datalist>
<input type="submit">
</form>
</div>
<!-- Display Area -->
<div>
<?php
if(isset($_POST['frompaintings']))
{
$item = $_POST['frompaintings'] ;
//MySQL Query to extract row by Painting Name
$result = mysqli_query($con,"SELECT * FROM Paintings WHERE `ArtName` = '$item'");
while($row = mysqli_fetch_array($result))
{
echo '<p>' . $row['ArtName'] . '</p>' ;
echo '<p>' . $row['ArtistName'] . '</p>' ;
echo '<p>' . $row['Price'] . '</p>' ;
echo '<p>' . $row['FileName'] . '</p>' ;
echo '' ;
}
}
?>
</div>
</body>
</html>
表结构为:ID int(11)| ArtName tinytext | ArtDescription文字| ArtistName tinytext | ArtistDescription文字|价格bigint(11)| FileName varchar(5555)
答案 0 :(得分:1)
要使您的数据可编辑,只需输入以下代码(将您的行作为html输入的值)
<input name="ArtName" type="text" size="32" value="<?=$row['ArtName']?>">
<input accept="ArtistName" type="text" size="32" value="<?=$row['ArtistName']?>">
<input name="Price" type="text" size="32" value="<?=$row['Price']?>">
<input name="FileName" type="text" size="32" value="<?=$row['FileName']?>">
要更新此字段,您应该使用html表单
发送它们<form action="editpainting-save.php" method="post" enctype="multipart/form-data">
<input ...>
<input ...>
</form>
使用以下命令
进行editpainting-save.php<?
$update_query="UPDATE Paintings SET
ArtName='".$_POST['ArtName']."',
ArtName='".$_POST['ArtName']."',
ArtName='".$_POST['ArtName']."',
ArtName='".$_POST['ArtName']."'
LIMIT 1";
$mysqli->query($update_query);
?>
答案 1 :(得分:0)