Skip to content

Commit 294279e

Browse files
committed
Final Update, not complete
1 parent 3fdebdb commit 294279e

File tree

3 files changed

+224
-0
lines changed

3 files changed

+224
-0
lines changed

db.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
try {
99
$bd=new PDO('mysql:host='.$host.';dbname='.$dbName, $user, $mdp);
1010
$bd->exec("SET NAMES 'utf8'");
11+
// echo "Connected to DB";
1112
}
1213
catch (Exception $e) {
1314
echo 'Error connecting to DB';

samples.php

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,127 @@
11
<?php
22
include_once('header.php');
33
include_once('footer.php');
4+
include_once('db.php');
5+
if(isset($_SESSION['id']))
6+
{
7+
$creatorID = $_SESSION['id'];
8+
}
9+
$sampleName = $genre = $instrument = $bpm = "";
10+
if (!isset($_POST['addSample']) ) {
11+
//un champ obligatoire
12+
if ( !empty($_POST['sampleName']) )
13+
{
14+
$sampleName = trim($_POST['sampleName']) ;
15+
}
16+
else
17+
{
18+
$mistakes['sampleName'] = true;
19+
}
20+
21+
if ( !empty($_POST['genre'])){
22+
$genre = trim($_POST['genre']) ;
23+
}
24+
else
25+
{
26+
$mistakes['genre'] = true;
27+
}
28+
29+
if ( !empty($_POST['instrument'])){
30+
$instrument = trim($_POST['instrument']) ;
31+
}
32+
else
33+
{
34+
$mistakes['instrument'] = true;
35+
}
36+
37+
if ( !empty($_POST['bpm'])){
38+
$bpm = trim($_POST['bpm']) ;
39+
}
40+
else
41+
{
42+
$mistakes['bpm'] = true;
43+
}
44+
45+
46+
47+
48+
//un champ obligatoire avec certaines valeurs rejetées
49+
50+
51+
52+
53+
//s'il n'y a pas d'erreur...
54+
if (empty($mistakes))
55+
{
56+
include("db.php");
57+
58+
$req=$bd->prepare('INSERT INTO samples (sampleName,genre,instrument,bpm,creatorID) VALUES (:sampleName,:genre,:instrument,:bpm,:creatorID)');
59+
$req->bindValue(':sampleName', $sampleName, PDO::PARAM_STR);
60+
$req->bindValue(':genre', $genre, PDO::PARAM_STR);
61+
$req->bindValue(':instrument', $instrument, PDO::PARAM_STR);
62+
$req->bindValue(':bpm', $bpm, PDO::PARAM_STR);
63+
$req->bindValue(':creatorID', $creatorID, PDO::PARAM_STR);
64+
echo '<pre>' . print_r($_SESSION, TRUE) . '</pre>';
65+
$req->execute();
66+
$req->closeCursor();
67+
header("Location:samples.php");
68+
exit();
69+
70+
}
71+
else{
72+
print_r($mistakes);
73+
}
74+
}
75+
76+
$host = 'localhost';
77+
$dbname = 'samplitek';
78+
$usern = 'root';
79+
$passw = '';
80+
$dsn = "mysql:host=$host;dbname=$dbname";
81+
// get all users
82+
$sql = "SELECT * FROM samples";
83+
84+
try{
85+
$pdo = new PDO($dsn, $usern, $passw);
86+
$stmt = $pdo->query($sql);
87+
88+
if($stmt === false){
89+
die("Error");
90+
}
91+
92+
}catch (PDOException $e){
93+
echo $e->getMessage();
94+
}
95+
496
?>
597
<p>Samples Here</p>
98+
<form action="samples.php" method="post">
99+
<input type="text" name="sampleName" id="sampleName" required="" placeholder="Sample Name">
100+
<input type="text" name="genre" id="genre" required="" placeholder="Genre">
101+
<input type="text" name="instrument" id="instrument" required="" placeholder="Instrument">
102+
<input type="text" name="bpm" id="name" required="" placeholder="BPM">
103+
<input type="submit" name="addSample" placeholder="Upload the sample">
104+
</form>
105+
106+
<table>
107+
<thead>
108+
<tr>
109+
<th>ID</th>
110+
<th>Sample Name</th>
111+
<th>Genre</th>
112+
<th>Instrument</th>
113+
<th>BPM</th>
114+
</tr>
115+
</thead>
116+
<tbody>
117+
<?php while($row = $stmt->fetch(PDO::FETCH_ASSOC)) : ?>
118+
<tr>
119+
<td><?php echo htmlspecialchars($row['id']); ?></td>
120+
<td><?php echo htmlspecialchars($row['sampleName']); ?></td>
121+
<td><?php echo htmlspecialchars($row['genre']); ?></td>
122+
<td><?php echo htmlspecialchars($row['instrument']); ?></td>
123+
<td><?php echo htmlspecialchars($row['bpm']); ?></td>
124+
</tr>
125+
<?php endwhile; ?>
126+
</tbody>
127+
</table>

songs.php

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,106 @@
11
<?php
22
include_once('header.php');
33
include_once('footer.php');
4+
include_once('db.php');
5+
if(isset($_SESSION['id']))
6+
{
7+
$creatorID = $_SESSION['id'];
8+
}
9+
$songName = $genreS = $bpm = "";
10+
if (!isset($_POST['addSong']) ) {
11+
//un champ obligatoire
12+
if ( !empty($_POST['songName']) )
13+
{
14+
$songName = trim($_POST['songName']) ;
15+
}
16+
else
17+
{
18+
$mistakes['songName'] = true;
19+
}
20+
21+
if ( !empty($_POST['genreS'])){
22+
$genreSS = trim($_POST['genreS']) ;
23+
}
24+
else
25+
{
26+
$mistakes['genreS'] = true;
27+
}
28+
29+
if ( !empty($_POST['bpmS'])){
30+
$bpmS = trim($_POST['bpmS']) ;
31+
}
32+
else
33+
{
34+
$mistakes['bpmS'] = true;
35+
}
36+
37+
//s'il n'y a pas d'erreur...
38+
if (empty($mistakes))
39+
{
40+
include("db.php");
41+
42+
$req=$bd->prepare('INSERT INTO songs (songName,genre,bpm,creatorID) VALUES (:songName,:genre,:bpm,:creatorID)');
43+
$req->bindParam(':songName', $songName, PDO::PARAM_STR);
44+
$req->bindParam(':genre', $genreS, PDO::PARAM_STR);
45+
$req->bindParam(':bpm', $bpmS, PDO::PARAM_STR);
46+
$req->bindParam(':creatorID', $creatorID, PDO::PARAM_STR);
47+
$req->execute();
48+
$req->closeCursor();
49+
header("Location:songs.php");
50+
exit();
51+
52+
}
53+
else{
54+
print_r($mistakes);
55+
}
56+
}
57+
58+
$host = 'localhost';
59+
$dbname = 'samplitek';
60+
$usern = 'root';
61+
$passw = '';
62+
$dsn = "mysql:host=$host;dbname=$dbname";
63+
// get all users
64+
$sql = "SELECT * FROM songs";
65+
66+
try{
67+
$pdo = new PDO($dsn, $usern, $passw);
68+
$stmt = $pdo->query($sql);
69+
70+
if($stmt === false){
71+
die("Error");
72+
}
73+
74+
}catch (PDOException $e){
75+
echo $e->getMessage();
76+
}
77+
478
?>
579
<p>Songs Here</p>
80+
<form action="songs.php" method="post">
81+
<input type="text" name="songName" id="songName" required="" placeholder="Song Name">
82+
<input type="text" name="genreS" id="genreS" required="" placeholder="Genre">
83+
<input type="text" name="bpms" id="bpmS" required="" placeholder="BPM">
84+
<input type="submit" name="addSong" required="Upload the song ">
85+
</form>
86+
87+
<table>
88+
<thead>
89+
<tr>
90+
<th>ID</th>
91+
<th>Song Name</th>
92+
<th>Genre</th>
93+
<th>BPM</th>
94+
</tr>
95+
</thead>
96+
<tbody>
97+
<?php while($row = $stmt->fetch(PDO::FETCH_ASSOC)) : ?>
98+
<tr>
99+
<td><?php echo htmlspecialchars($row['id']); ?></td>
100+
<td><?php echo htmlspecialchars($row['songName']); ?></td>
101+
<td><?php echo htmlspecialchars($row['genre']); ?></td>
102+
<td><?php echo htmlspecialchars($row['bpm']); ?></td>
103+
</tr>
104+
<?php endwhile; ?>
105+
</tbody>
106+
</table>

0 commit comments

Comments
 (0)