简体   繁体   English

MYSQL 查询与 html 输入

[英]MYSQL query with html input

Hello I am trying to create a query for a table that shows the performances performed by the artist selected in the form's drop down menu.您好,我正在尝试为一个表格创建一个查询,该表格显示了在表格下拉菜单中选择的艺术家的表演。 I am receiving an undefined index error but I used the same piece of code to reference the input earlier in my code so I am confused.我收到一个未定义的索引错误,但我使用同一段代码在我的代码中引用了前面的输入,所以我很困惑。 any help is appreciated.任何帮助表示赞赏。

Query error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax;查询错误:未捕获的 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\final exam\test.php:72 Stack trace: #0 C:\inetpub\wwwroot\courses\354\Students\raw51419\final exam\test.php(72): PDO->prepare('\nSELECT a.first...') #1 {main} thrown in C:\inetpub\wwwroot\courses\354\Students\raw51419\final exam\test.php on line 72 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>";

The order of things in SELECT is strict. SELECT中的事物顺序是严格的。 The common items are:常见的项目有:

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

Many of those clauses are optional.其中许多条款是可选的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM