PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
CREATE TABLE singers ( id INT AUTO_INCREMENT PRIMARY KEY, name TEXT NOT NULL, pronunciation TEXT NOT NULL, created_at DATETIME DEFAULT CURRENT_TIMESTAMP, updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ); CREATE TABLE genres ( id INT AUTO_INCREMENT PRIMARY KEY, name TEXT NOT NULL, created_at DATETIME DEFAULT CURRENT_TIMESTAMP, updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ); CREATE TABLE songs ( id INT AUTO_INCREMENT PRIMARY KEY, name TEXT NOT NULL, pronunciation TEXT NOT NULL, singer_id INT NOT NULL, genre_id INT, created_at DATETIME DEFAULT CURRENT_TIMESTAMP, updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, FOREIGN KEY (singer_id) REFERENCES singers (id), FOREIGN KEY (genre_id) REFERENCES genres (id) ); CREATE TABLE reservations ( id INT AUTO_INCREMENT PRIMARY KEY, song_id INT NOT NULL, created_at DATETIME DEFAULT CURRENT_TIMESTAMP, updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, FOREIGN KEY (song_id) REFERENCES songs (id) ); INSERT INTO singers (name, pronunciation) VALUES ('Creepy Nuts(R-指定&DJ松永)', 'クリーピーナッツアールシテイアンドディージェイマツナガ'); INSERT INTO singers (name, pronunciation) VALUES ('高橋洋子', 'タカハシヨウコ'); INSERT INTO singers (name, pronunciation) VALUES ('YOASOBI', 'ヨアソビ'); INSERT INTO singers (name, pronunciation) VALUES ('Vaundy', 'バウンディ'); INSERT INTO singers (name, pronunciation) VALUES ('中川翔子', 'ナカガワショウコ'); INSERT INTO singers (name, pronunciation) VALUES ('tuki.', 'ツキ'); INSERT INTO singers (name, pronunciation) VALUES ('優里', 'ユウリ'); INSERT INTO singers (name, pronunciation) VALUES ('あいみょん', 'アイミョン'); INSERT INTO singers (name, pronunciation) VALUES ('back number', 'バックナンバー'); INSERT INTO singers (name, pronunciation) VALUES ('Mrs.GREEN APPLE', 'ミセスグリーンアップル'); INSERT INTO singers (name, pronunciation) VALUES ('Saucy dog', 'サウシードッグ'); INSERT INTO singers (name, pronunciation) VALUES ('aiko', 'アイコ'); INSERT INTO singers (name, pronunciation) VALUES ('菅田将暉', 'スダマサキ'); INSERT INTO singers (name, pronunciation) VALUES ('Taylor Swift', 'テイラー・スウィフト'); INSERT INTO singers (name, pronunciation) VALUES ('シャルル', 'シャルル'); INSERT INTO singers (name, pronunciation) VALUES ('美空ひばり', 'ミソラヒバリ'); INSERT INTO genres (name) VALUES ('-'); INSERT INTO genres (name) VALUES ('アニメ'); INSERT INTO genres (name) VALUES ('ボーカロイド'); INSERT INTO genres (name) VALUES ('演歌'); INSERT INTO genres (name) VALUES ('洋楽'); INSERT INTO songs (name, pronunciation, singer_id, genre_id) VALUES ('Bling-Bang-Bang-Born', 'ブリンバンバンボン', 1, 2); INSERT INTO songs (name, pronunciation, singer_id, genre_id) VALUES ('残酷な天使のテーゼ', 'ザンコクナテンシノテーゼ', 2, 2); INSERT INTO songs (name, pronunciation, singer_id, genre_id) VALUES ('残酷な天使のテーゼ', 'ザンコクナテンシノテーゼ', 5, 2); INSERT INTO songs (name, pronunciation, singer_id, genre_id) VALUES ('アイドル', 'アイドル', 3, 2); INSERT INTO songs (name, pronunciation, singer_id, genre_id) VALUES ('夜に駆ける', 'ヨルニカケル', 3, 1); INSERT INTO songs (name, pronunciation, singer_id, genre_id) VALUES ('怪獣の花唄', 'カイジュウノハナウタ', 4, 1); INSERT INTO songs (name, pronunciation, singer_id, genre_id) VALUES ('タイムパラドックス', 'タイムパラドックス', 5, 2); INSERT INTO songs (name, pronunciation, singer_id, genre_id) VALUES ('晩餐歌', 'ばんさんか', 6, 1); INSERT INTO songs (name, pronunciation, singer_id, genre_id) VALUES ('ドライフラワー', 'ドライフラワー', 7, 1); INSERT INTO songs (name, pronunciation, singer_id, genre_id) VALUES ('マリーゴールド', 'マリーゴールド', 8, 1); INSERT INTO songs (name, pronunciation, singer_id, genre_id) VALUES ('水平線', 'スイヘイセン', 9, 1); INSERT INTO songs (name, pronunciation, singer_id, genre_id) VALUES ('高嶺の花子さん', 'タカネノハナコサン', 9, 1); INSERT INTO songs (name, pronunciation, singer_id, genre_id) VALUES ('青と夏', 'アオトナツ',10, 1); INSERT INTO songs (name, pronunciation, singer_id, genre_id) VALUES ('ケセラセラ', 'ケセラセラ',10, 1); INSERT INTO songs (name, pronunciation, singer_id, genre_id) VALUES ('シンデレラボーイ', 'シンデレラボーイ',11, 1); INSERT INTO songs (name, pronunciation, singer_id, genre_id) VALUES ('いつか', 'イツカ',11, 1); INSERT INTO songs (name, pronunciation, singer_id, genre_id) VALUES ('カブトムシ', 'カブトムシ',12, 1); INSERT INTO songs (name, pronunciation, singer_id, genre_id) VALUES ('虹', 'ニジ',13, 2); INSERT INTO songs (name, pronunciation, singer_id, genre_id) VALUES ('Love Story', 'ラブストーリー',14, 5); INSERT INTO songs (name, pronunciation, singer_id, genre_id) VALUES ('22', 'トゥエンティートゥー',14, 5); INSERT INTO songs (name, pronunciation, singer_id, genre_id) VALUES ('バルーン', 'バルーン',15, 3); INSERT INTO songs (name, pronunciation, singer_id, genre_id) VALUES ('川の流れのように', 'カワノナガレノヨウ二',16, 4);
Copy Clear
Copy Format Clear
<?php // Assuming $mysqli is already defined and connected to the database // Function to handle the song reservation function reserveSong($mysqli, $song_id) { // SQL query to insert the reservation $sql = "INSERT INTO reservations (song_id) VALUES (?)"; $stmt = $mysqli->prepare($sql); $stmt->bind_param('i', $song_id); $stmt->execute(); $stmt->close(); } // Function to display reserved songs function displayReservedSongs($mysqli) { // SQL query to get reserved songs $sql = " SELECT songs.name AS song_name, singers.name AS singer_name FROM reservations JOIN songs ON reservations.song_id = songs.id JOIN singers ON songs.singer_id = singers.id "; $result = $mysqli->query($sql); // HTML output echo "<h1>Reserved Songs</h1>"; echo "<table border='1'>"; echo "<tr><th>Song Name</th><th>Singer Name</th></tr>"; while ($row = $result->fetch_assoc()) { echo "<tr>"; echo "<td>" . htmlspecialchars($row['song_name'], ENT_QUOTES, 'UTF-8') . "</td>"; echo "<td>" . htmlspecialchars($row['singer_name'], ENT_QUOTES, 'UTF-8') . "</td>"; echo "</tr>"; } echo "</table>"; $result->free(); } // Check if a song_id has been submitted for reservation if (isset($_POST['song_id'])) { $song_id = $_POST['song_id']; reserveSong($mysqli, $song_id); } // Display the reserved songs displayReservedSongs($mysqli); ?> <!-- HTML form to reserve a song --> <form action="" method="post"> <label for="song_id">Select Song ID to Reserve:</label> <input type="number" id="song_id" name="song_id" required> <input type="submit" value="Reserve"> </form>
Show:  
Copy Clear