Jump to content

Archived

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

localhost

Dropdown box not showing options...

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]

Share this post


Link to post
Share on other sites
if(mysql_num_rows($result2) < 1)
{
to this

if(mysql_num_rows($result2) > 0)
{


and this

<form action="add_forum.php" method="POST">

to this

<form action=" " method="POST">

just try ok

Share this post


Link to post
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.

Share this post


Link to post
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";

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.