par
jmc41320 » 06 févr. 2014, 11:38
bonjour,
ma table comporte deux champs , id et nom
je voudrais afficher le nom connaissant l'id mais j'ai une erreur mysql_fetch_assoc()
<?php
$id= $_POST['id'];
$db = mysql_connect('localhost', 'root', '');
// on sélectionne la base
mysql_select_db('mabase',$db);
// on crée la requête SQL
$sql = 'SELECT id,nom FROM matable where id=$id';
// on envoie la requête
$req = mysql_query($sql);
$data = mysql_fetch_assoc($req);
// on affiche les informations de l'enregistrement selectionne
echo ''.$data['id'].' '.$data['nom'].'';
// on ferme la connexion à mysql
mysql_close()
merci
bonjour,
ma table comporte deux champs , id et nom
je voudrais afficher le nom connaissant l'id mais j'ai une erreur mysql_fetch_assoc()
[php]<?php
$id= $_POST['id'];
$db = mysql_connect('localhost', 'root', '');
// on sélectionne la base
mysql_select_db('mabase',$db);
// on crée la requête SQL
$sql = 'SELECT id,nom FROM matable where id=$id';
// on envoie la requête
$req = mysql_query($sql);
$data = mysql_fetch_assoc($req);
// on affiche les informations de l'enregistrement selectionne
echo ''.$data['id'].' '.$data['nom'].'';
// on ferme la connexion à mysql
mysql_close()[/php]
merci