Gwendo69
Messages postés147Date d'inscriptionlundi 29 septembre 2008StatutMembreDernière intervention28 juin 2013
-
27 mars 2009 à 00:17
kohntark
Messages postés3705Date d'inscriptionlundi 5 juillet 2004StatutMembreDernière intervention27 avril 2012
-
27 mars 2009 à 08:23
Bonsoir,
lorsque j'essaie de faire ces requêtes.
//récupère l'identifiant de l'artiste
$identifiant = 'SELECT id_artiste FROM artiste WHERE nom_artiste="'.$choix.'"';
//supprime les données inscrites dans la table
$supprimer = 'DELETE FROM information WHERE id_type="1" AND id_artiste="'.$identifiant.'"';
//lance le req
mysql_query ($identifiant) or die ('Erreur SQL !'.$identifiant.'
'.mysql_error());
mysql_query ($supprimer) or die ('Erreur SQL !'.$supprimer.'
'.mysql_error());
J'ai ce message d'erreur:
Erreur SQL !DELETE FROM information WHERE id_type="1" AND id_artiste="SELECT id_artiste FROM artiste WHERE nom_artiste="blabla""
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'nom de l'artiste choisi""' at line 1
Savez vous quelle est la bonne syntaxe?
Merci, Gwendo.
kohntark
Messages postés3705Date d'inscriptionlundi 5 juillet 2004StatutMembreDernière intervention27 avril 201230 27 mars 2009 à 06:46
Salut,
En fait $identifiant est une chaîne de caractères :
$identifiant = 'SELECT id_artiste FROM artiste WHERE nom_artiste="'.$choix.'"';
$supprimer = 'DELETE FROM information WHERE id_type="1" AND id_artiste="'.$identifiant.'"';
donc plutôt un truc comme ça :
$sql_identifiant = "SELECT id_artiste FROM artiste WHERE nom_artiste='$choix'";
$identifiant = mysql_query ($sql_identifiant) or die ('Erreur SQL ! '.$sql_identifiant.'
'.mysql_error());
$supprimer = "DELETE FROM information WHERE id_type=1 AND id_artiste='$identifiant'";
mysql_query ($supprimer) or die ('Erreur SQL !'.$supprimer.'
'.mysql_error());
Gwendo69
Messages postés147Date d'inscriptionlundi 29 septembre 2008StatutMembreDernière intervention28 juin 2013 27 mars 2009 à 08:11
En effet il fallait mettre 1 et pas "1". Merci aussi.
ça en crée une nouvelle quand je fait ça juste après:
$inserer = 'INSERT INTO information VALUES("","'.$bio.'","'.$identifiant.'","1")';
mysql_query ($inserer) or die ('Erreur SQL !'.$inserer.'
'.mysql_error());
kohntark
Messages postés3705Date d'inscriptionlundi 5 juillet 2004StatutMembreDernière intervention27 avril 201230 27 mars 2009 à 08:23
En effet, j'ai fais une erreur pour la suppression :
$sql_identifiant = "SELECT id_artiste FROM artiste WHERE nom_artiste='$choix'";
$q = mysql_query ($sql_identifiant) or die ('Erreur SQL ! '.$sql_identifiant.'
'.mysql_error());
$identifiant = mysql_fetch_array($q, MYSQL_NUM);
$supprimer = "DELETE FROM information WHERE id_type=1 AND id_artiste='$identifiant[0]'";
mysql_query ($supprimer) or die ('Erreur SQL !'.$supprimer.'
'.mysql_error());
Je ne connais pas la structure de ta table ni le reste de ton script mais à mon avis tu te complique la vie.
Une seule requête devrait suffire, non ?