Alienware Posted February 10, 2009 Share Posted February 10, 2009 Ok so im kind of stuck... I am trying to make a feature on my forum where a member of staff can Lock a topic to new replies. But im stuck at the second hurdle... I have created a new row in my MySQL database as so- Database table- maintopics Database row- Lock Enum ('Unlocked','locked') now.... I now added onto my code- $lock = mysql_query("SELECT 'Lock' FROM `maintopics` WHERE `id` = '$topicid' LIMIT 1")or die(mysql_error()); $arr = mysql_fetch_array($query); if ($topicid == "unlocked"){ and }elseif ($lock == "locked"){ This is all i am getting- ?> $lock = mysql_query("SELECT 'Lock' FROM `maintopics` WHERE `id` = '$topicid' LIMIT 1")or die(mysql_error()); $arr = mysql_fetch_array($query); if ($lock == "unlocked"){ Reply Message }elseif ($lock == "locked"){ Sorry This Topic is Locked to New Replies ?> Back to forum If anyone can help it will be appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/144567-need-some-help-with-lock-topic/ Share on other sites More sharing options...
Alienware Posted February 10, 2009 Author Share Posted February 10, 2009 Can nobody help me? Quote Link to comment https://forums.phpfreaks.com/topic/144567-need-some-help-with-lock-topic/#findComment-758672 Share on other sites More sharing options...
Philip Posted February 10, 2009 Share Posted February 10, 2009 Show more code please. Also, Enum ('Unlocked','locked') and $lock == "unlocked" can cause problems (case wise) Quote Link to comment https://forums.phpfreaks.com/topic/144567-need-some-help-with-lock-topic/#findComment-758675 Share on other sites More sharing options...
Alienware Posted February 10, 2009 Author Share Posted February 10, 2009 I changed few things around hoping to fix it but nothing has worked. here is the full code- <?php require('connections/db.php'); require('connections/require.php'); require("connections/replace.php"); echo ("<link rel=\"stylesheet\" href=\"connections/style.css\" type=\"text/css\">"); $query = mysql_query("SELECT * FROM `players` WHERE `playername` = '$player' LIMIT 1")or die(mysql_error()); $arr = mysql_fetch_array($query); $family = $arr['family']; $qu = mysql_query("SELECT * FROM `family` WHERE `name` = '$family' LIMIT 1")or die(mysql_error()); $ar = mysql_fetch_array($qu); $boss = $ar['boss']; $rhm = $ar['rhm']; $lhm = $ar['lhm']; $loc = $ar['location']; $topicid = $_GET['id']; $forum = $_GET['forum']; $forum_look=$_GET['forum_look']; $forum_count = 10; $index = 0; $chk = mysql_query("SELECT * FROM `staff` WHERE `playername` = '$player' LIMIT 1")or die(mysql_error()); $numm = mysql_numrows($chk); if ($forum != "main" && $forum != "family" && $forum != $loc && $numm == 0){ $error = "This is not your family forum."; error($error); exit; } if (! isset($forum_look) ) { $forum_look = 0; } $qry = mysql_query("SELECT * FROM `mainreplys` WHERE `topicid` = '$topicid' AND `forum` = '$forum' ORDER BY `id` DESC LIMIT $forum_look , $forum_count")or die(mysql_error()); $num = mysql_numrows($qry); $q = mysql_query("SELECT * FROM `maintopics` WHERE `id` = '$topicid' AND `forum` = '$forum' LIMIT 1")or die(mysql_error()); $a = mysql_fetch_array($q); function index_navigation($index, $count, $num) { $forum = $_GET['forum']; $topicid = $_GET['id']; print ("<center>"); if ($index != 0) { print " <a href=\"viewtopic2.php?id=".$topicid."&forum=".$forum."&forum_look=" . ($index - $count) . "\">Previous</a> "; } if ($num >= $count) { print " <a href=\"viewtopic2.php?id=".$topicid."&forum=".$forum."&forum_look=" . ($index + $count) . "\">Next</a> "; } print ("</center>"); } if (strip_tags($_POST['submit'])){ $forum = $_POST['forum']; $reply = $_POST['reply_message']; $reply = strip_tags(addslashes($reply)); mysql_query("INSERT INTO `mainreplys` ( `id` , `poster` , `message` , `forum` , `date` , `topicid` ) VALUES ( '' , '$player' , '$reply' , '$forum' , '$date' , '$a[id]' )")or die(mysql_error()); $upd = "Reply added."; upd($upd); print ("<META HTTP-EQUIV=\"refresh\" content=\"1; url=viewtopic2.php?id=".$topicid."&forum=".$forum."\">"); $newposts = $arr['forumposts'] + 1; mysql_query("UPDATE `players` SET `forumposts` = '$newposts' WHERE `playername` = '$player' LIMIT 1")or die(mysql_error()); $newreps = $a['replys'] + 1; $time = time(); mysql_query("UPDATE `maintopics` SET `replys` = '$newreps' , `lastreply` = '$time' WHERE `id` = '$a[id]' LIMIT 1")or die(mysql_error()); } ?> <table width="75%" align="center" class="tbl" border="1" bordercolor="#FFFFFF"> <tr> <td align="center" class="hdr" colspan="2"><b><? print $a[topic]; ?> - <a href="../profile.php?player=<? print $a[creator]; ?>"><? print $a[creator]; ?></a> wrote:</td></tr> <tr><td class="tbl" colspan="2"><br /><? print replace($a[text]); ?><br /><br /></td></tr> </table> <br> <? while($ary = mysql_fetch_array($qry)){ $qr = mysql_query("SELECT * FROM `players` WHERE `playername` = '$ary[poster]' LIMIT 1")or die(mysql_error()); $ar = mysql_fetch_array($qr); ?> <table width="60%" align="center" class="tbl" border="1" bordercolor="#FFFFFF"> <tr><td align="center" width="90%" class="hdr"> <b><a href="../profile.php?player=<? print $ary[poster]; ?>"><? print $ary[poster]; ?></a></b> wrote: <tr> <td class="tbl"><br /><? print replace($ary[message]); ?><br /><br /></td> </tr> <br> <? } ?> </table> <?php $lock = mysql_query("SELECT * FROM `maintopics` WHERE `id` = '$topicid' AND `Lock` = '$lock' LIMIT 1")or die(mysql_error()); if ($lock == `locked`){ echo "<table><tr><th>Sorry This Topic is Locked to New Replies</th></table>" elseif ($lock == `unlocked`){ <p></p> echo "<form action="" method="post"> <input type="hidden" name="forum" value="<? print $forum; ?>"> <table width="45%" align="center" class="tbl"> <tr><td align="center" class="hdr">Reply</td></tr> <tr><td align="center" class="sub">Message</td></tr> <tr><td align="center" class="tbl"> <textarea name="reply_message" cols="30" rows="3"></textarea> </td></tr> <tr><td align="center" class="sub"></td></tr> <tr><td align="center" class="tbl"> <? sub(submit,"Post Reply"); ?> </td></tr> </table> </form>" } ?> <br /><center><a href="forum2.php?forum=<? print $forum; ?>">Back to forum</a></center><br /><br /> <? index_navigation($forum_look, $forum_count, $num); ?> Quote Link to comment https://forums.phpfreaks.com/topic/144567-need-some-help-with-lock-topic/#findComment-758677 Share on other sites More sharing options...
Philip Posted February 10, 2009 Share Posted February 10, 2009 Oh boy, your error is easy to spot: if ($lock == `locked`){ echo "<table><tr><th>Sorry This Topic is Locked to New Replies</th></table>" elseif ($lock == `unlocked`){ <p></p> echo "<form action="" method="post"> <input type="hidden" name="forum" value="<? print $forum; ?>"> <table width="45%" align="center" class="tbl"> <tr><td align="center" class="hdr">Reply</td></tr> <tr><td align="center" class="sub">Message</td></tr> <tr><td align="center" class="tbl"> <textarea name="reply_message" cols="30" rows="3"></textarea> </td></tr> <tr><td align="center" class="sub"></td></tr> <tr><td align="center" class="tbl"> <? sub(submit,"Post Reply"); ?> </td></tr> </table> </form>" } There is a lot wrong with that code, try this: if ($lock == 'locked'){ echo "<table><tr><th>Sorry This Topic is Locked to New Replies</th></table>"; // add semicolon } else { // had no echo for the <p> tags // and the quotes were not escaped. Easy solution, take the html out of PHP. ?> <p></p> <form action="" method="post"> <input type="hidden" name="forum" value="<?php echo $forum; ?>"> <table width="45%" align="center" class="tbl"> <tr><td align="center" class="hdr">Reply</td></tr> <tr><td align="center" class="sub">Message</td></tr> <tr><td align="center" class="tbl"> <textarea name="reply_message" cols="30" rows="3"></textarea> </td></tr> <tr><td align="center" class="sub"></td></tr> <tr><td align="center" class="tbl"> <?php sub(submit,"Post Reply"); ?> </td></tr> </table> </form> <?php } Also, be careful using short tags (<?). I replaced them with normal tags (<?php), but there are still some in your code. Edit: I'm looking through the rest of your code, and there are a lot of typos. $numm = mysql_numrows($chk); should be $numm = mysql_num_rows($chk);, etc. Take a look over your code again. Quote Link to comment https://forums.phpfreaks.com/topic/144567-need-some-help-with-lock-topic/#findComment-758678 Share on other sites More sharing options...
Alienware Posted February 10, 2009 Author Share Posted February 10, 2009 thankyou, that took all the errors away and set the page back to how it should be. however... When i set the topic to "locked" it still doesn't show the "topic is locked" line... it still alows a user to post a topic :s im puzzled Quote Link to comment https://forums.phpfreaks.com/topic/144567-need-some-help-with-lock-topic/#findComment-758681 Share on other sites More sharing options...
Philip Posted February 10, 2009 Share Posted February 10, 2009 Can you tell me what's wrong with this statement: $lock = mysql_query("SELECT * FROM `maintopics` WHERE `id` = '$topicid' AND `Lock` = '$lock' LIMIT 1")or die(mysql_error()); perhaps the variable $lock? Quote Link to comment https://forums.phpfreaks.com/topic/144567-need-some-help-with-lock-topic/#findComment-758683 Share on other sites More sharing options...
Alienware Posted February 10, 2009 Author Share Posted February 10, 2009 Im not sure what eltse to do with the $lock should i just change the variable name? from $lock to $toplock perhaps? Quote Link to comment https://forums.phpfreaks.com/topic/144567-need-some-help-with-lock-topic/#findComment-758684 Share on other sites More sharing options...
Alienware Posted February 10, 2009 Author Share Posted February 10, 2009 Tried and it didnt work Quote Link to comment https://forums.phpfreaks.com/topic/144567-need-some-help-with-lock-topic/#findComment-758688 Share on other sites More sharing options...
Philip Posted February 10, 2009 Share Posted February 10, 2009 Okay, in your query you have AND `Lock`='$lock', however I can't find where you are getting $lock from, AND you're setting the query result to that same variable name ($lock) Try: $lock = mysql_query("SELECT * FROM `maintopics` WHERE `id` = '$topicid' LIMIT 1")or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/144567-need-some-help-with-lock-topic/#findComment-758689 Share on other sites More sharing options...
Alienware Posted February 10, 2009 Author Share Posted February 10, 2009 Still no joy... Ill post my MySQL for "maintopics", dont knwo if it will help but ill post it id int(11) = > >= < <= != LIKE NOT LIKE IS NULL IS NOT NULL creator varchar(20) latin1_swedish_ci LIKE LIKE %...% NOT LIKE = != REGEXP NOT REGEXP IS NULL IS NOT NULL topic text latin1_swedish_ci LIKE LIKE %...% NOT LIKE = != REGEXP NOT REGEXP IS NULL IS NOT NULL text text latin1_swedish_ci LIKE LIKE %...% NOT LIKE = != REGEXP NOT REGEXP IS NULL IS NOT NULL forum enum('main', 'family', 'New Zealand', 'Australia', 'USA', 'England', 'South Africa', 'Cuba', 'Unknown', 'otf', 'des', 'ent', 'class') latin1_swedish_ci = != IS NULL IS NOT NULL main family New Zealand Australia USA England South Africa Cuba Unknown otf des ent class replys int(11) = > >= < <= != LIKE NOT LIKE IS NULL IS NOT NULL lastreply varchar(255) latin1_swedish_ci LIKE LIKE %...% NOT LIKE = != REGEXP NOT REGEXP IS NULL IS NOT NULL s enum('0', '1') latin1_swedish_ci = != IS NULL IS NOT NULL 0 1 l enum('0', '1') latin1_swedish_ci = != IS NULL IS NOT NULL 0 1 Lock enum('unlocked', 'locked') latin1_swedish_ci = != IS NULL IS NOT NULL unlocked locked Quote Link to comment https://forums.phpfreaks.com/topic/144567-need-some-help-with-lock-topic/#findComment-758692 Share on other sites More sharing options...
Philip Posted February 10, 2009 Share Posted February 10, 2009 Uhh, that doesn't really help Here's what I would suggest, and trust me, it will help you not only here but in the future as well. Go through your code, using an editor with a syntax highlighter (you probably already are.) Comment and indent your code properly. There are a lot of mysql queries, that I don't really have a clue on what they are doing, lol. Example, and I'm just guessing: // Get replies: $qry = mysql_query("SELECT * FROM `mainreplys` WHERE `topicid` = '$topicid' AND `forum` = '$forum' ORDER BY `id` DESC LIMIT $forum_look , $forum_count")or die(mysql_error()); A lot of your queries could also be combined into fewer queries. Have you ever used a JOIN? Quote Link to comment https://forums.phpfreaks.com/topic/144567-need-some-help-with-lock-topic/#findComment-758696 Share on other sites More sharing options...
Alienware Posted February 10, 2009 Author Share Posted February 10, 2009 Im actually just really properly learning PHP i didn't write the script, my friend wrote it and gave it to me... So im kind of trying to program and learn at the same time. I doubt i will sort this though, i have a feeling its because of how i have run the query... but i know no other way... looks like im gonna have no luck lol. Thanks anyway for all of your help. Quote Link to comment https://forums.phpfreaks.com/topic/144567-need-some-help-with-lock-topic/#findComment-758697 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.