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
https://forums.phpfreaks.com/topic/14085-dropdown-box-not-showing-options/
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";

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.