cs_Rimb0
Messages postés103Date d'inscriptiondimanche 23 janvier 2005StatutMembreDernière intervention 3 septembre 2008
-
6 mai 2006 à 15:16
coucou747
Messages postés12303Date d'inscriptionmardi 10 février 2004StatutMembreDernière intervention30 juillet 2012
-
6 mai 2006 à 15:54
Bonjour à tous,
je voudrais vérifier qu'une valeur n'existe pas déjà dans une table.
Voici ce que j'ai écrit :
Adresse de ma page : index.php?cat=cool
$cat=$_GET['cat'];
$q=mysql_query('SELECT cat FROM section WHERE cat="'.$cat.'"'); // on fait un select
if ($q==FALSE){ // s'il n'existe pas, on ecrit
echo 'marche pas';
} else {
echo 'marche';
}
Ce script ne marche pas, et je pense que ça vient de FALSE.
Avez vous une idée ? Pensez vous qu'il faille faire un SELECT pour vérifier qu'une valeur n'existe pas dans une colonne ?
coucou747
Messages postés12303Date d'inscriptionmardi 10 février 2004StatutMembreDernière intervention30 juillet 201244 6 mai 2006 à 15:41
Salut,
$cat=$_GET['cat'];
$q=mysql_query('SELECT cat FROM section WHERE cat="'.$cat.'"')or die(mysql_error()); // on fait un select
if (mysql_fetch_array($q)===FALSE){ // s'il n'existe pas, on ecrit
echo 'marche pas';
} else {
echo 'marche';
}
In a dream, I saw me, drop dead... U was there, U cried... It was just a dream, if I die, U won't cry, maybe, U'll be happy