Jump to content


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


Visible ENUM

Recommended Posts

Hi, my first CMS I'm working on is almost near completion. However, I've came across an annoying problem that I thought would be easy to implement.

The basic idea is that users submit sports articles, and moderators of my choice will get the chance to approve or deny any submitted article for public viewing.

In My SQL I added: [code]ALTER TABLE articles ADD COLUMN
visible ENUM('N', 'Y') NOT NULL;[/code]

and added a checkmark that said 'visible' in the admin article listings.

So, I know the query I'm meant to use is [code]WHERE visible='Y'[/code] but to which query do I add it?

I have current articles that I've wrote myself and right now they are all set to invisible. I wish to make some of those visible by using the edit article page that I've made:

[code]if (isset($_POST['articletext'])):
  // The article's details have
  // been updated.
  $id = $_POST['id'];
  $aid = $_POST['aid'];
  $articletext = $_POST['articletext'];

  $sql = "UPDATE articles SET
          WHERE id='$id'";
  if (mysql_query($sql)) {
    echo '<p>Article details updated.</p>';
  } else {
    exit('<p>Error updating article details: ' .
        mysql_error() . '</p>');

  // Delete all existing entries for this
  // article from the article category table
  $ok = mysql_query("DELETE FROM articlecategory
                    WHERE articleid='$id'");
  if (!$ok) {
    exit('<p>Error removing article from all categories:' .
        mysql_error() . '</p>');

  if (isset($_POST['cats'])) {
    $cats = $_POST['cats'];
  } else {
    $cats = array();

  foreach ($cats as $catID) {
    $sql = "INSERT IGNORE INTO articlecategory
            SET articleid='$id', categoryid='$catID'";
    $ok = @mysql_query($sql);
    if (!$ok) {
      echo "<p>Error inserting article into category $catID: " .
          mysql_error() . '</p>';


<p><a href="articles.php">New article search</a></p>

<?php else: // Allow the user to edit the article

  $id = $_GET['id'];

  $article = @mysql_query(
    "SELECT articletext, authorid FROM articles WHERE id='$id'");
  if (!$article) {
    exit('<p>Error fetching article details: ' .
        mysql_error() . '</p>');

  $article = mysql_fetch_array($article);

  $articletext = $article['articletext'];
  $authid = $article['authorid'];

  // Convert HTML special characters
  // in database value for use in
  // an HTML document.
  $articletext = htmlspecialchars($articletext);

  // Get lists of authors and categories for
  // the select box and checkboxes.
  $authors = @mysql_query('SELECT id, name FROM author');
  if (!$authors) {
    exit('<p>Unable to obtain author list from the database.</p>');

  $cats = @mysql_query('SELECT id, name FROM category');
  if (!$cats) {
    exit('<p>Unable to obtain category list from the database.</p>');

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>Edit the article:<br />
<textarea name="articletext" rows="15" cols="45">
<?php echo $articletext; ?></textarea>
<select name="aid" size="1">
  while ($author = mysql_fetch_array($authors)) {
    $aid = $author['id'];
    $aname = htmlspecialchars($author['name']);
    if ($aid == $authid) {
      echo "<option selected='selected' value='$aid'>$aname</option>\n";
    } else {
      echo "<option value='$aid'>$aname</option>\n";
<p>In categories:<br />
  while ($cat = mysql_fetch_array($cats)) {
    $cid = $cat['id'];
    $cname = htmlspecialchars($cat['name']);

    // Check if the article is in this category
    $result = @mysql_query(
      "SELECT * FROM articlecategory
      WHERE articleid='$id' AND categoryid='$cid'");
    if (!$result) {
      exit('<p>Error fetching article details: ' .
          mysql_error() . '</p>');

    // mysql_num_rows gives the number of entries
    // in a result set. In this case, if the result
    // contains one or more rows, the condition
    // below will evaluate to true to indicate that
    // the article does belong to the category, and the
    // checkbox should be checked.
    if (mysql_num_rows($result)) {
      echo "<input type='checkbox' checked='checked' name='cats[]' value='$cid' />$cname<br />\n";
    } else {
      echo "<input type='checkbox' name='cats[]' value='$cid' />$cname<br />\n";
<input type="hidden" name="id" value="<?php echo $id; ?>" />
<input type="submit" value="SUBMIT" />

<?php endif; ?>[/code]

Share this post

Link to post
Share on other sites
For a one time fix for your articles, first look in the database and find out your authorid.  For my example, I'm assuming your authorid is 133, if you have a different one (probably) just change the SQL below to use your number instead of 133.

then from mysql

or from MysqlAdmin of your favorite flavor,

run this command:

UPDATE articles SET visible = 'Y' WHERE authorid = 133;

This will enable all your articles.



Share this post

Link to post
Share on other sites


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.