Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [http://uap.unnes.ac.id/buku/Web/MySQL%20&%20PHP/Apress%20-%20PHP%20for%20Absolute%20Beginners%20(2009).pdf]
- CREATE TABLE IF NOT EXISTS artists
- (
- artist_id INT PRIMARY KEY AUTO_INCREMENT,
- artist_name VARCHAR(150)
- )
- CREATE TABLE IF NOT EXISTS albums
- (
- album_id INT PRIMARY KEY AUTO_INCREMENT,
- artist_id INT,
- album_name VARCHAR(150)
- )
- [INSERT Albums {id(1,2,3...) + album_name}]
- <?php
- if($_SERVER['REQUEST_METHOD']=='POST')
- {
- // Open a MySQL connection
- $link = new mysqli('localhost', 'root', '', 'music');
- if(!$link) {
- die('Connection failed: ' . $mysqli->error());
- }
- // Create and execute a MySQL query
- $sql = "SELECT album_name FROM albums WHERE artist_id=?";
- if($stmt = $link->prepare($sql))
- {
- $stmt->bind_param('i', $_POST['artist']);
- $stmt->execute();
- $stmt->bind_result($album);
- while($stmt->fetch()) {
- printf("Album: %s<br />", $album);
- }
- $stmt->close();
- }
- // Close the connection
- $link->close();
- }
- else {
- ?>
- <form method="post">
- <label for="artist">Select an Artist:</label>
- <select name="artist">
- <option value="1">Bon Iver</option>
- <option value="2">Feist</option>
- </select>
- <input type="submit" />
- </form>
- <?php } // End else ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement