php - 单击“添加到播放列表按钮”后,从 PHP 数据库中获取特定行以添加到新的空数据库中
问题描述
我的网络编程课程有一个小组项目,我们正在创建一个简单的音乐网站,并使用 phpmyadmin 为每种类型创建了一个数据库,我们有一个添加到播放列表按钮,应该将所选歌曲添加到空数据库中,但我们不能弄清楚为什么它不起作用。
<div id="navbar">
<table>
<tr>
<td>
<font size="6"><a href="home_page.php"><b>Home</a></font>
</td>
<td>
<font size="6"><a href="pop_page.php"><b>Pop</a></font>
</td>
<td>
<font size="6"><a href="Rap_Page.php"><b>Hip-Hop</a></font>
</td>
<td>
<font size="6"><a href="rock_.php"><b>Rock</a></font>
</td>
<td>
<font size="6"><a href="country_page.php"><b>Country</a></font>
</td>
<td>
<font size="6"><a href="alternative_page.php"><b>Alternative</a></font>
</td>
<td>
<font size="6"><a href="playlist_page.php"><b>My Playlist</a></font>
</td>
</tr>
</table>
</div>
<!-- End of navbar div -->
<br>
<!-- PHP code here to display the appropriate databse table (genre/playlist) -->
<?php
$dbc = mysqli_connect("localhost", "root", "", "Music Website") or die("Bad Connect:" . mysqli_connect_error());
$sql = "SELECT * FROM AltMusic";
$result = mysqli_query($dbc, $sql) or die("Bad Query: $sql");
echo "<table id = 'database'>";
echo "<tr id = 'tableHead'>
<td class = 'titleCells'>Title</td>
<td class = 'titleCells'>Artist</td>
<td class = 'titleCells'>Album</td>
<td class = 'titleCells'>YouTube</td>
<td class = 'titleCells'>Genre</td>
<td class = 'titleCells'>Add to Playlist</td>
</tr>";
while ($row = mysqli_fetch_assoc($result)) {
echo "<tr>
<td class = 'cells'>{$row['Title']}</td>
<td class = 'cells'>{$row['Artist']}</td>
<td class = 'cells'>{$row['Album']}</td>
<td class = 'cells'><a href='" . $row['YouTube'] . "'target = _blank>" .
$row['YouTube'] . "</a></td>
<td class = 'cells'>{$row['Genre']}</td>
<td id = 'add' class = 'cells'>" ?>
<form action='' method='POST'>
<input type='submit' name='submit' value="+"/>
</form><?
if (isset($_POST['submit'])) {
$sql2 = "INSERT INTO Playlist(`ID`, `Title`, `Artist`, `Album`, `YouTube`,
`Genre`)
SELECT `ID`, `Title`, `Artist`, `Album`, `YouTube`, `Genre`FROM Pop
WHERE ";
}
echo "</td>
</tr>";
}
echo "</table>";
if ($result->num_rows > 0) {
// output data of each row
while ($row = $result->fetch_assoc()) {
echo "<br> Title: " . $row['Title'] . " Artist: " . $row["Artist"] . " Album: " .
$row["Album"] . "YouTube: " . $row["YouTube"] . "Genre: " . $row["Genre"] . "Add to Playlist: " .
$row["Add to Playlist"] . "<br>";
}
} else {
echo "0 results";
}
$dbc->close();
?>
<!-- Bookmark to allow uesrs to return to the top of the page once at the bottom -->
<a href=#top>
<font size="6">Back to top</font>
</a>
我曾尝试使用 isset($_POST("") 添加它,但它只能弄清楚如何获取整个数组而不是一次选择。
请考虑到我以及我小组中的所有成员都对 Web 编程相当陌生。如果我没有正确发布或没有对我正在尝试做的事情给出足够具体的想法,请以体贴的方式告诉我。感谢您提供任何帮助。
解决方案
推荐阅读
- xcode - iOS Build 已上传但在 iTunes 中不可见
- java - AndroidX Jetifier Mockito java.lang.SecurityException:com/samsung/android/sdk/accessory/SAAgentV2.class 的 SHA-256 摘要错误
- excel - excel根据条件输入最新值
- javascript - 如何使用 Firebase 发送唯一的注册链接?
- html - 对具有多个行跨度的表格中的单元格进行排序
- vue.js - 带有一个 prepage 的多个 VueJS 应用程序 - 导航到每个应用程序而无需重定向
- wpf - 隐藏组合框项目
- python - Python SoundDeviceStream 写入/读取下溢/溢出错误
- reactjs - 如何处理 React HOC 嵌套
- laravel - 授权标头仅在 GET 请求(nginx)上未到达 API