我有这个问题,我的查询不会将数据从数据库拉到网站,我已经尝试了很多东西,但我得到一个偏移错误或根本没有出现。有人可以看一下吗?
带下拉菜单的网站 -
$dbc = @mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die ('Could not connect to MySQL: ' . mysqli_connect_error() );
//echo "Connected to MySQL<br>";
$q = "SELECT artistname FROM tbl_artists ORDER BY artistname ASC";
$r = @mysqli_query ($dbc, $q);
// Form start
echo '<form action="php/process_dropdown.php" method="post">
<select name="selection">
<option value=""> -- Please select an Artist -- </option>';
// Fetch and print all the records:
while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
echo '<option>' . $row['artistname'] . '</option>
';
}
echo '<p><input type="submit" value="Send"></p>
</select>
</form>'; // End of form.
?>
下拉流程
$dbc = @mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die ('Could not connect to MySQL: ' . mysqli_connect_error() );
$name = $_POST['selection'];
$q = "SELECT tbl_songs.songtitle, tbl_songs.yearrelease, tbl_artists.genre, tbl_songs.price
FROM tbl_artists INNER JOIN tbl_songs ON tbl_artists.artistID = tbl_songs.artistID
WHERE (((tbl_artists.artistID)='$name'))";
$r = @mysqli_query ($dbc, $q) or die("Error: ".mysqli_error($dbc));
// Table header.
echo '<table>
<tr>
<th scope="col">Song</th>
<th scope="col">Year Released</th>
<th scope="col">Genre</th>
<th scope="col">Price</th>
</tr>
';
// Fetch and print all the records:
while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
echo '<tr><td>' . $row['songtitle'] . '</td><td>' . $row['yearrelease'] . '</td><td>' . $row['genre'] . '</td><td>' . $row['price'] . '</td></tr> ';
}
echo '</table>'; // Close the table.
?>
谢谢。
答案 0 :(得分:1)
修改强>:
$link = mysqli_connect('host', 'user', 'password', 'database');
转变为:
$dbc = mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die
('Could not connect to MySQL: ' . mysqli_connect_error() );
//echo "Connected to MySQL<br>";
$q = "SELECT artistname FROM tbl_artists ORDER BY artistname ASC";
$r = mysqli_query ($dbc, $q);
..................
看到这个:
WHERE (((tbl_artists.artistID)='$name'))";
你错过了:tbl_songs
。在$name
之前。
此外,使用@并不好,因为它隐藏了错误消息。 (这是一个穷人 脚本)