Insert into PHP/MySql
Hey guys
I have been scripting a musicupload system for my website
All my script works exepte the upload side. Please have a look @my script and tell me where I went wrong:
I use 3 tables:
1 artiste, 2. Albums 3. Songs would like to use one form to insert values
NB: script commented in french, my english not to good
Script
--------
//Premier cas : nouvel artiste
//On passe le message dans une série de fonction
$artiste = $_POST['artiste'];
$album = $_POST['album'];
$titre = $_POST['titres'];
$temps = time();
if (empty($artiste) || empty($album))
{
echo 'Artiste ou Album ne doivent etre vide,
Recommencer';
}
else //Si jamais les champs ne sont pas vides
{
//On entre l'artiste dans la base de donnée
$query=$db->prepare('INSERT INTO artistes (artiste_nom)
VALUES (:artiste)');
$query->bindValue(':artiste', $artiste, PDO::PARAM_INT);
$query->execute();
$idartiste = $db->lastInsertId(); $query->CloseCursor();
//Puis on entre l' album
$query=$db->prepare('INSERT INTO albums
(artiste_id, album_titre,)
VALUES (:id, :album)');
$query->bindValue(':id', $idartiste, PDO::PARAM_INT);
$query->bindValue(':album', $album, PDO::PARAM_STR);
$query->execute();
$idalbum = $db->lastInsertId();
$query->CloseCursor();
// enfin la chanson
$query=$db->prepare('INSERT INTO chansons
(album_id, chanson_titre,)
VALUES (:id, :chanson)');
$query->bindValue(':id', $idalbum, PDO::PARAM_INT);
$query->bindValue(':chanson', $titre, PDO::PARAM_STR);
$query->execute();
$query->CloseCursor();
//Et un petit message
echo' Uploads completed';
Echo 'Chant: ' . $titres . ': ' . $artiste;
}
I used the same thing to post messages it works.
Will appreciate any help. Thanx
Greg K posted this at 02:36 — 3rd November 2011.
He has: 2,145 posts
Joined: Nov 2003
Can you explain more. Are you getting errors, if so, what are they? What is it doing you were not expecting to do and/or what wasn't it doing that you were expecting it to do?
The more details you can provide the better we an help you.
Without knowing what exactly the intent of your site is, one thing I did notice is that if someone uploads 50 songs by the same artist, you are going to have 50 entries in the Artist table, all the same. You should run a query that checks to see if the artist is already in the table before inserting it. (Same for album)
-Greg
Dj@n posted this at 04:20 — 3rd November 2011.
They have: 4 posts
Joined: Oct 2011
Thanks Greg, I found where I went wrong,
I had in mind the test side (see if artist exist in table ...) But wanted just to see if my script works. In my post "Uploads and Downloads u may see the upload script.
Thank u guy 4 ur attention!
Am working on the hole script now, will give feedbacks!
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.