Jump to content

Dropdown box not showing options...


localhost

Recommended Posts

This is supposed to show the categories' names so I can choose which category to put the forum in but its showing up blank! and Inserts cid  as 0.

[code=php:0]
<?php

include('../connect.php');

if(isset($_POST['submit']) && !empty($_POST['title']))
{
$title = $_POST['title'];
$description = $_POST['description'];
$cid = $_POST['cid'];

$query = "INSERT INTO forums (`id`, `cid`, `title`, `description`) VALUES ('NULL', '$cid', '$title', '$description')";
$result = mysql_query($query) or die(mysql_error());

echo "Forum successfully added.";
}

$query2 = "SELECT id, title from categories ORDER BY title ASC";
$result2 = mysql_query($query2) or die(mysql_error());

if(mysql_num_rows($result2) < 1)
{
echo "Categories must first exist before forums. (Parents before children!)";
}

?>

<form action="add_forum.php" method="POST">
Forum Title:
<input type="text" name="title" />
<br />
Forum Description:
<input type="text" name="description" />
<Br />
Parent Category:
<select name="cid">
<?
  while($row = mysql_fetch_array($result2))
  {
      echo "<option value=\"". $row['id'] ."\">". $row['title'] ."</option> \n";
  }
?>
</select>
<br />
<input type="submit" name="submit" value="Add" />
</form>
[/code]
Link to comment
Share on other sites

Both of those statements are horribly wrong man....if the number of rows is higher than 0, that means there are categories, meaning it shouldn't display the message.

Also, using "" and add_forum.php do the exact same thing, I've used both.
Link to comment
Share on other sites

      echo "<option value=\"". $row['id'] ."\">". $row['title'] ."</option> \n";

what this mean above exsplain

id what? NULL with the title of NULL

this looks better

$query2 = "SELECT categories.id, categories.title from categories WHERE id='NULL' ORDER BY title ASC";
and
echo "<option value=\"". $row['title'] ."\">". $row['title'] ."</option> \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.