簡體   English   中英

MYSQL 查詢與 html 輸入

[英]MYSQL query with html input

您好,我正在嘗試為一個表格創建一個查詢,該表格顯示了在表格下拉菜單中選擇的藝術家的表演。 我收到一個未定義的索引錯誤,但我使用同一段代碼在我的代碼中引用了前面的輸入,所以我很困惑。 任何幫助表示贊賞。

查詢錯誤:未捕獲的 PDOException:SQLSTATE[42000]:語法錯誤或訪問沖突:1064 您的 SQL 語法有錯誤; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INNER JOIN performance p ON p.artist_id = a.artist_id INNER JOIN recording r ON' at line 4 in C:\inetpub\wwwroot\courses\354 \Students\raw51419\期末考試\test.php:72 堆棧跟蹤:#0 C:\inetpub\wwwroot\courses\354\Students\raw51419\期末考試\test.php(72): nSELECT a.first...') #1 {main} 在第 72 行的 C:\inetpub\wwwroot\courses\354\Students\raw51419\final Exam\test.php 中拋出

    $content ="";
require_once("db.php");
$query = "
SELECT a.first_name, a.last_name, s.genre, s.title, s.year,r.length, p.venue, p.date
FROM artist a
WHERE artist_id = ?
INNER JOIN performance p ON p.artist_id = a.artist_id 
INNER JOIN recording r ON p.recording_id = r.recording_id
INNER JOIN song s ON p.song_id = s.song_id";
$stmt = $conn->prepare($query);
$stmt->execute([$artid]);
foreach ($stmt as $row) {

$content .=
  "<tr>
    <td>{$row["first_name"]}</td>
    <td>{$row["last_name"]}</td>
    <td>{$row["title"]}</td>
    <td>{$row["year"]}</td>
    <td>{$row["genre"]}</td>
    <td>{$row["date"]}</td>
    <td>{$row["venue"]}</td>
    <td>{$row["length"]}</td>
  </tr>";
  }

$content =
  "<table>
  <h4>Performances:</h4>
  <table class='table table-bordered table-striped'>
    <tr>
        <th>First</th>
        <th>Last</th>
        <th>Title</th>
        <th>Year</th>
        <th>Genre</th>
        <th>Date</th>
        <th>Venue</th>
        <th>Length</th>
    </tr>
    {$content}
    </table>";

SELECT中的事物順序是嚴格的。 常見的項目有:

SELECT ...
FROM ...
JOIN ...   ON ...
WHERE ...
GROUP BY ...
HAVING ...
ORDER BY ...
LIMIT ...

其中許多條款是可選的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM