PHP Mysql 下拉列表问题 - 它不更新
PHP Mysql Dropdown List Issue - It doesn't Update
我的项目有问题,希望您能帮助我找到解决方案。我的数据库中有一个名为 albums 的 table,它有 8 列,分别是 id、album_name、图像、艺术家、公司、流派、价格、类别。我为我的项目创建了一个后端以更新网站。我可以更新类别列旁边的所有列,因为它是一个列表,其中有 3 个下拉项,它们是我的项目类别,它们是“新发行、流行专辑、特别优惠。在我的 index.php 我只显示了新发行类别的 4 张专辑、流行专辑类别的 4 张专辑、特别优惠类别的 4 张专辑。我的 index.php 中的代码是这样的:
<tr>
<td width='120'>Category:</td>
<td>
<select name = 'categories'>
<option value = 'releases'>New Releases</option>
<option value = 'popular'>Popular Songs</option>
<option value = 'offers'>Special Offers</option>
</select>
</td>
</tr>
我的后端代码是这样的:
<?php
include('../../includes/database/db.php');
$id = $_GET['id'];
$album_name = $_POST['album_name'];
$img = $_POST['image'];
$artist = $_POST['artist'];
$company = $_POST['company'];
$genre = $_POST['genre'];
$price = $_POST['price'];
$category = $_POST['category'];
if ($album_name!='' && $artist!='' && $company!='' && genre!='' && $price!='' && $category!='') {
$sql = mysqli_query($dbconn, "UPDATE albums SET album_name = '".$album_name."',image = '".$img."',artist = '".$artist."',company = '".$company."',genre = '".$genre."',price = '".$price."',category = '".$category."' WHERE id='$id'");
echo'<meta http-equiv="refresh" content="0;url=../index.php?page=albums&action=list">';
}else{
echo'<meta http-equiv="refresh" content="0;url=../index.php?page=albums&action=edit&msg=empty&id='.$id.'">';
}
?>
我想更新类别列,例如,如果一张专辑属于新发行类别,我想使用下拉列表将其放入另一个类别,例如特价商品。我正在努力实现这一点,但它不会更新。我的 table 中的所有其他列都工作正常。
谢谢。
您的 HTML 代码构造不正确。
<select>
...
</select>
此字段必须包含名称属性。
<select name="category">
...
</select>
发布后您可以在 PHP 代码中引用它
echo $_POST['category'];
我的项目有问题,希望您能帮助我找到解决方案。我的数据库中有一个名为 albums 的 table,它有 8 列,分别是 id、album_name、图像、艺术家、公司、流派、价格、类别。我为我的项目创建了一个后端以更新网站。我可以更新类别列旁边的所有列,因为它是一个列表,其中有 3 个下拉项,它们是我的项目类别,它们是“新发行、流行专辑、特别优惠。在我的 index.php 我只显示了新发行类别的 4 张专辑、流行专辑类别的 4 张专辑、特别优惠类别的 4 张专辑。我的 index.php 中的代码是这样的:
<tr>
<td width='120'>Category:</td>
<td>
<select name = 'categories'>
<option value = 'releases'>New Releases</option>
<option value = 'popular'>Popular Songs</option>
<option value = 'offers'>Special Offers</option>
</select>
</td>
</tr>
我的后端代码是这样的:
<?php
include('../../includes/database/db.php');
$id = $_GET['id'];
$album_name = $_POST['album_name'];
$img = $_POST['image'];
$artist = $_POST['artist'];
$company = $_POST['company'];
$genre = $_POST['genre'];
$price = $_POST['price'];
$category = $_POST['category'];
if ($album_name!='' && $artist!='' && $company!='' && genre!='' && $price!='' && $category!='') {
$sql = mysqli_query($dbconn, "UPDATE albums SET album_name = '".$album_name."',image = '".$img."',artist = '".$artist."',company = '".$company."',genre = '".$genre."',price = '".$price."',category = '".$category."' WHERE id='$id'");
echo'<meta http-equiv="refresh" content="0;url=../index.php?page=albums&action=list">';
}else{
echo'<meta http-equiv="refresh" content="0;url=../index.php?page=albums&action=edit&msg=empty&id='.$id.'">';
}
?>
我想更新类别列,例如,如果一张专辑属于新发行类别,我想使用下拉列表将其放入另一个类别,例如特价商品。我正在努力实现这一点,但它不会更新。我的 table 中的所有其他列都工作正常。
谢谢。
您的 HTML 代码构造不正确。
<select>
...
</select>
此字段必须包含名称属性。
<select name="category">
...
</select>
发布后您可以在 PHP 代码中引用它
echo $_POST['category'];