1

I'm creating a forum in PHP and using MySql as a database, and was wondering how I could check if a MySql field topic_locked was equal to 1. If it isn't, the reply code would be displayed. How can I check this, and if you can help me find how to check this, how could I set it to 1 through the forum?

4
  • 2
    Post your code and database table structure.
    – kittycat
    Jan 3, 2013 at 5:05
  • 1
    We need something to work with. Database structure? Existing code? Jan 3, 2013 at 5:06
  • 1
    Hey provide some table structure and what you have tried.... Jan 3, 2013 at 5:06
  • WHERE topic_locked <> 1 or may be CASE WHEN topic_locked = 1 THEN ... ELSE something else END?? Jan 3, 2013 at 5:13

1 Answer 1

1

I dont know your code. But I am sharing simple program to check a mysql field's value.

<?php

// Database select and connect to host


$sql= mysql_query("SELECT topic_locked FROM table WHERE Id='your_id'");
$res= mysql_fetch_array($sql);

$value= $res['topic_locked'];

if($value=='1')
{
// reply code
}
?>

Update asked,

<?php
        if(isset($_POST['update']))
        {
        $id= $_POST['id'];
        //Database select and connect to host
        mysql_query("UPDATE table SET topic_locked='1' WHERE Id='$id'");
        }
   ?>
        <form action="" method="post">
        <input type="hidden" name="id" value="your_id" />
        <input type="submit" name="update" />
        </form>
4
  • That has helped me a ton. For the update part, how can I have a button perform that? Jan 4, 2013 at 3:53
  • Thanks for updating so quickly! It only shows the if. $sql= mysql_query("SELECT topic_locked FROM topics"); $res= mysql_fetch_array($sql); $value= $res['topic_locked']; if($value=='1') { echo '<tr><td colspan="2"><p>Sorry; this topic has been locked.</p></td></tr>'; } else { echo '<tr><td colspan="2"><h2>Reply:</h2><br /> <form method="post" action="reply.php?id=' . $row['topic_id'] . '"> <textarea name="reply-content"></textarea><br /><br /> <input id="button" type="submit" value="Submit reply" /> </form></td></tr>'; } Jan 4, 2013 at 4:26
  • What should I put for the where condition? Jan 4, 2013 at 22:24
  • @user1640021: You should really mark this answer as accepted. The responder gave a good answer to a multipart question that was ask rather poorly. Aug 7, 2013 at 16:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.