Jump to content

let only 1 register user see a link


chanfuterboy

Recommended Posts

hi,

 

I try but I am doing something wrong. I want the user ' lady1 ' in table of username, be able to see a link that i called crew2.php. the rest users will not see the link, help me figur out it, in my code below

 

if(mysql_num_rows($sql) > 0){

// Loop through the results
while($row = mysql_fetch_array($sql)){
	$username = $row['username'];
	$password = $row['password'];
	$email = $row['email'];

if ($username == lady1)
	 {
	print "click, click > <a href='crew2.php'>here</a> <";
	}
else
	{

	}
	$all_stuff =  "<b>Admin name</b>:<b><font face='Tahoma' size='3'> $username</font></b> <hr size=1>

	               <br>Adm Pass: $password
	               <br>Adm email: $email";
	if($i % $tblWidth ){
		echo "<td align='center' valign='top' bgcolor='#F2F2F2'>$all_stuff</td>";
	}else{
		//else then print column number 2 etc for the next loop.
		echo "<tr></tr>";
		echo "<td align='center' cellpadding='10' valign='top' bgcolor='#F2F2F2'>$all_stuff</td>";
	}
	//add only 1 for the loop ($i).
	$i++;

 

 

Link to comment
https://forums.phpfreaks.com/topic/169627-let-only-1-register-user-see-a-link/
Share on other sites

Give something like this a try, I broke your code down so it's easier to read. I took out a bunch of the echos and prints and just used HTML code instead.

<?php
if(mysql_num_rows($sql) > 0){
   
   // Loop through the results
   while($row = mysql_fetch_array($sql)){
      $username = $row['username'];
      $password = $row['password'];
      $email = $row['email'];
      
   if ($username == lady1)
       { ?>

      click, click > <a href='crew2.php'>here</a> <

  <?php    }
else
      {
         
      } ?>

     <b>Admin name</b>:<b><font face='Tahoma' size='3'> $username</font></b> <hr size=1>

                     <br>Adm Pass: $password
                     <br>Adm email: $email
<?php
      if($i % $tblWidth ){
    ?>
         <td align='center' valign='top' bgcolor='#F2F2F2'><?php echo $all_stuff; ?></td>
<?php
      }else{
         //else then print column number 2 etc for the next loop.
?>
         </tr><tr>
         <td align='center' cellpadding='10' valign='top' bgcolor='#F2F2F2'><?php echo $all_stuff; ?></td>
<?php
      }
      //add only 1 for the loop ($i).
      $i++; ?>

 

I don't know how you have your table set up, I'm assuming that you have omitted some of that code.

#1 you're trying to compare 'lady1' as a string NOT a constant to the $username variable which means you should encase that string with quotes..

 

#2 when a user logs in you should store their username and other often used information in a session...

 

so if you do store them in a session

 

if ($_SESSION['username'] == 'lady1') {

}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.