Jump to content

[SOLVED] Code not doing what it should


mike12255

Recommended Posts

I got the current code:

 

if($session->isAdmin()){
      print" &nbsp-<A href='deletetopic.php?id=$id'>Delete Topic ";
  
  $query  = "SELECT locked FROM forumtutorial_posts WERE postid = $id";

  $result = mysql_query($query);
   
   print $result;
   
  if ($result < 1){// if locked is set to 0 (unlocked)
	  
	  print" &nbsp-<A href='locktopic.php?id=$id'>Lock Topic";
  }else{//otherwise show unlock
	   print" &nbsp-<A href='unlocktopic.php?id=$id'>Unlock Topic";
	  
	  
  }
	  
  



  }

 

 

I know that locked for the postid it should be using (13) is set to 1 so it should show unlock topic, but instead it shows lock topic. Can anyone see why?

Link to comment
Share on other sites

"$result" is a database result set. You can't print it to the page and it's value is meaningless for comparison purposes. You need to extract the records from the result set.

 

Also, you aren't even using closing tags on your anchors. Sloppy code will always be errror prone.

 

Try this:

if($session->isAdmin())
{
    $query  = "SELECT locked FROM forumtutorial_posts WERE postid = $id";
    print "Query: $query<br /><br />\n"; //For debugging only

    $result = mysql_query($query) or die(mysql_error());;
    $record = mysql_fetch_assoc($result);
   
    print" &nbsp-<A href='deletetopic.php?id=$id'>Delete Topic</a> \n";
    if ($record['locked'] < 1)
    {
        // if locked is set to 0 (unlocked)
        print" &nbsp-<A href='locktopic.php?id=$id'>Lock Topic</a>\n";
    }
    else
    {
        //otherwise show unlock
        print" &nbsp-<A href='unlocktopic.php?id=$id'>Unlock Topic</a>\n";
    }
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.