Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <style type="text/css">
- .tg {border-collapse:collapse;border-spacing:0;}
- .tg td{font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}
- .tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}
- .tg .tg-yw4l{vertical-align:top}
- </style>
- <body>
- CREATE (doesn't work)
- <form name="test" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
- artist: <input type="text" name="artist"><br>
- title: <input type="text" name="title"><br>
- category: <input type="text" name="title"><br>
- played: <input type="text" name="title"><br>
- tracks: <input type="text" name="title"><br>
- reldate: <input type="text" name="title"><br>
- <input type="submit">
- </form>
- </body>
- </html>
- <?php
- function connect() {
- $servername = "localhost";
- $username = "root";
- $password = "";
- $dbname = "labexam";
- // Create connection
- $conn = new mysqli($servername, $username, $password, $dbname);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- }
- if($_POST){
- if(isset($_POST['create'])){
- create();
- }
- /*elseif(isset($_GET['read'])){
- read();
- }*/
- }
- function create() {
- // prepare and bind
- $conn = connect();
- $stmt = $conn->prepare("INSERT INTO cdset (artist, title, category, played, tracks, reldate) VALUES (?, ?, ?, ?, ?, ?)");
- $stmt->bind_param("sssiis", $artist, $title, $category, $played, $tracks, $reldate);
- echo $stmt;
- $artist = $_POST['artist'];
- $title = $_POST['title'];
- $category = $_POST['category'];
- $played = $_POST['played'];
- $tracks = $_POST['tracks'];
- $reldate = $_POST['reldate'];
- $stmt->execute();
- return $conn;
- }
- //$stmt->close();
- //$conn->close();
- ?>
- <?php
- $servername = "localhost";
- $username = "root";
- $password = "";
- $dbname = "labexam";
- // Create connection
- $conn = new mysqli($servername, $username, $password, $dbname);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- $sql = "SELECT * FROM cdset";
- $result = $conn->query($sql);
- if ($result->num_rows > 0) {
- //echo "test";
- // output data of each row
- echo "READ
- <table class='tg'>
- <tr>
- <th class='tg-yw4l'>id</th>
- <th class='tg-yw4l'>artist</th>
- <th class='tg-yw4l'>title</th>
- <th class='tg-yw4l'>category</th>
- <th class='tg-yw4l'>played</th>
- <th class='tg-yw4l'>tracks</th>
- <th class='tg-yw4l'>reldate</th>
- </tr>";
- while($row = $result->fetch_assoc()) {
- echo "<tr>
- <th class='tg-yw4l'>".$row["id"]."</th>
- <th class='tg-yw4l'>".$row["artist"]."</th>
- <th class='tg-yw4l'>".$row["title"]."</th>
- <th class='tg-yw4l'>".$row["category"]."</th>
- <th class='tg-yw4l'>".$row["played"]."</th>
- <th class='tg-yw4l'>".$row["tracks"]."</th>
- <th class='tg-yw4l'>".$row["reldate"]."</th>
- </tr>";
- }
- } else {
- echo "0 results";
- }
- echo "</table><br/>
- UPDATE<br/><br/>
- DELETE";
- $conn->close();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement