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
https://forums.phpfreaks.com/topic/141273-solved-code-not-doing-what-it-should/
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";
    }
}

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.