php - The user ID is not defined -
ok i'm trying list users in mysql , that's working when add profile.php?id=
else code user id not defined. how set wont user id not defined. here code:
<?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 members id defined if(isset($_get['user_id'])) { $id = intval($_get['user_id']); //we check if user exists $dn = mysql_query('select user_name, user_email users user_id="'.$id.'"'); if(mysql_num_rows($dn)>0) { $dnn = mysql_fetch_array($dn); //we display user datas ?> 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 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 /> user joined 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 not defined.'; } ?> users.php <?php //we ids, usernames , emails of members $req = mysql_query('select `user_id`, `user_name`, `user_email`, `user_sign_up_date` `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 } ?>
you query returning false on following line
$dn = mysql_query('select user_name, user_email users user_id="'.$id.'"');
you need find out why, should not attempt untill returns true:
$sql = sprintf("select user_name, user_email users user_id = %s", mysql_real_escape_string($id)); $dn = mysql_query($sql); if(!$dn){ echo "mysql_query() failed"; exit(); }
Comments
Post a Comment