Ok J'essaye de lister tous les utilisateurs dans mysql et cela fonctionne mais quand j'ajoute un profile.php?id=
j'obtiens mon code d'autre L'ID d'utilisateur n'est pas défini. comment puis-je le définir afin qu'il ne dise pas L'ID utilisateur n'est pas défini. voici mon code:L'ID utilisateur n'est pas défini
<?php
include('config/db.php');
?>
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password="password"; // Mysql password
$db_name="login"; // Database name
$tbl_name="users"; // Table name
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
//We check if the members ID is defined
if(isset($_GET['user_id']))
{
$id = intval($_GET['user_id']);
//We check if the user exists
$dn = mysql_query('select user_name, user_email from users where user_id="'.$id.'"');
if(mysql_num_rows($dn)>0)
{
$dnn = mysql_fetch_array($dn);
//We display the user datas
?>
This is the profile of "<?php echo htmlentities($dnn['user_name']); ?>" :
<table style="width:500px;">
<tr>
<td><?php
if($dnn['avatar']!='')
{
echo '<img src="'.htmlentities($dnn['avatar'], ENT_QUOTES, 'UTF-8').'" alt="Avatar" style="max-width:100px;max-height:100px;" />';
}
else
{
echo 'This user dont have an avatar.';
}
?></td>
<td class="left"><h1><?php echo htmlentities($dnn['user_name'], ENT_QUOTES, 'UTF- 8'); ?></h1>
Email: <?php echo htmlentities($dnn['user_email'], ENT_QUOTES, 'UTF-8'); ?><br />
This user joined the website on <?php echo date('Y/m/d',$dnn['signup_date']); ?> </td>
</tr>
</table>
<?php
}
else
{
echo 'This user dont exists.';
}
}
else
{
echo 'The user ID is not defined.';
}
?>
this is the users.php
<?php
//We get the IDs, usernames and emails of members
$req = mysql_query('SELECT `user_id`, `user_name`, `user_email`, `user_sign_up_date` FROM `users`');
while($dnn = mysql_fetch_array($req))
{
?>
<tr>
<td class="left"><?php echo $dnn['user_id']; ?></td>
<td class="left"><a href="profile.php?<?php echo $dnn['user_id']; ?>"><?php echo ($dnn['user_name']); ?></a></td>
<td class="left"><?php echo($dnn['user_email']); ?></td>
</tr>
<?php
}
?>
* "profile.php?' Id' = "* et vous utilisez' where user_id' - * ahem * –
[** Veuillez ne pas utiliser les fonctions 'mysql_ *' dans le nouveau code **] (http : //bit.ly/phpmsql). Ils ne sont plus maintenus [et sont officiellement obsolètes] (http://j.mp/XqV7Lp). Voir la [** boîte rouge **] (http://j.mp/Te9zIL)? En savoir plus sur [* instructions préparées *] (http://j.mp/T9hLWi) à la place, et utiliser [PDO] (http://php.net/pdo) ou [MySQLi] (http://php.net/ mysqli) - [cet article] (http://j.mp/QEx8IB) vous aidera à décider lequel. Si vous choisissez PDO, [voici un bon tutoriel] (http://j.mp/PoWehJ). – esqew
dans ma base de données le nom d'id est user_id et j'ai enlevé les fonctions de mysql et recevant toujours l'erreur L'ID d'utilisateur n'est pas défini. – user3783761