Jump to content

Trying to add another text area but I get an error message.


coolcam26

Recommended Posts

Hi,

 

I am trying to make a php website to create listings however I am having problems with the following code:

 

<?php
require_once("/home/a9653716/public_html/functions.php");
if(!$_SESSION['uid']){
    header("Location: index.php");
}

$id = mss($_GET['id']);

if ($id) {
    $sql = "SELECT * FROM `forum_sub_cats` WHERE `id`='" . $id . "'";
    $res = mysql_query($sql) or die(mysql_error());
    if (mysql_num_rows($res) == 0) {
        echo "The forum you are trying to create a topic on, does not exist!\n";
    } else {
        $row1 = mysql_fetch_assoc($res);
        if ($row1['admin'] == 1 && $admin_user_level == 0) {
            echo "You are not an administrator, therefore you cannot post on this forum!\n";
        } else {
            if (!$_POST['submit']) {
                echo "<table border=\"0\" cellspacing=\"3\" cellpadding=\"3\">\n";
                echo "<form method=\"post\" action=\"./index.php?act=create&id=".$id."\">\n";
                echo "<tr><td>Forum Sub Category</td><td><select name=\"cat\">\n";
                $sql2 = "SELECT * FROM `forum_cats` WHERE `admin` < " . $admin_user_level . "+1";
                $res2 = mysql_query($sql2) or die(mysql_error());
                while ($row = mysql_fetch_assoc($res2)) {
                    $sql3 = "SELECT * FROM `forum_sub_cats` WHERE `cid`='" . $row['id'] . "'";
                    $res3 = mysql_query($sql3) or die(mysql_error());

                    echo "<option value=\"0\">" . $row['name'] . "</option>\n";
                    while ($row2 = mysql_fetch_assoc($res3)) {
                        $selected = ($row2['id'] == $id) ? " SELECTED" : "";
                        echo "<option value=\"" . $row2['id'] . "\"" . $selected .
                            ">     " . $row2['name'] . "</option>\n";
                    }
                }
                echo "</select></td></tr>\n";
			echo "<tr><td>Topic Title</td><td><input type=\"text\" name=\"title\"></td></tr>\n";
			?>
                <script>edToolbar('message'); </script>
			<?php
			echo "<tr><td>Message</td><td><textarea id=\"message\" name=\"message\" class=\"ed\"></textarea></td></tr>\n";
			echo "<tr><td>Tags (Seperate with commas)</td><td><input type=\"text\" name=\"tags\"></td></tr>\n";
			echo "<tr><td colspan=\"2\" align=\"right\"><input type=\"submit\" name=\"submit\" value=\"Create Topic\"></td></tr>\n";
                echo "</form></table>\n";
            } else {
                $cat = mss($_POST['cat']);
                $title = mss($_POST['title']);
                $msg = mss($_POST['message']);
			$tags = mss($POST['tags']);

                if ($cat && $title && $msg && $tags) {
                    $sql = "SELECT admin FROM `forum_sub_cats` WHERE `id`='" . $cat . "'";
                    $res = mysql_query($sql) or die(mysql_error());
                    if (mysql_num_rows($res) == 0) {
                        echo "This forum sub category does not exist!\n";
                    } else {
                        $row = mysql_fetch_assoc($res);
                        if ($row['admin'] == 1 && $admin_user_level != 1) {
                            echo "You are not an admin therefore you cannot post a new topic on this forum!\n";
                        } else {
                            if (strlen($title) < 3 || strlen($title) > 32) {
                                echo "The title must be between 3 and 32 characters!\n";
                            } else {
                                if (strlen($msg) < 3 || strlen($msg) > 10000) {
                                    echo "The message must be between 3 and 10,000 characters!\n";
                                 } else {
								if (strlen($tags) < 2 || strlen($tags) > 200) {
									echo "You must submit at least 1 tag and the total length mustn't be more than 200 characters!\n";
								} else {
                                    $date = date("m-d-y") . " at " . date("h:i:s");
                                    $time = time();
                                    $sql2 = "INSERT INTO `forum_topics` (`cid`,`title`,`uid`,`date`,`time`,`message`,`tags`) VALUES('" .
                                        $cat . "','" . $title . "','" . $_SESSION['uid'] . "','" . $date . "','" . $time .
                                        "','" . $msg . "','" . $tags . "')";
                                    $res2 = mysql_query($sql2) or die(mysql_error());
                                    $tid = mysql_insert_id();
                                    topic_go($tid);
								}
							}
                            }
                        }
                    }
                } else {
                    echo "Please supply all the fields! \n";
                }
            }
        }
    }
} else {
    if (!$_POST['submit']) {
        echo "<table border=\"0\" cellspacing=\"3\" cellpadding=\"3\">\n";
        echo "<form method=\"post\" action=\"./index.php?act=create\">\n";
        echo "<tr><td>Forum Sub Category</td><td><select name=\"cat\">\n";
        $sql2 = "SELECT * FROM `forum_cats` WHERE `admin` < " . $admin_user_level . "+1";
        $res2 = mysql_query($sql2) or die(mysql_error());
        while ($row = mysql_fetch_assoc($res2)) {
            $sql3 = "SELECT * FROM `forum_sub_cats` WHERE `cid`='" . $row['id'] . "'";
            $res3 = mysql_query($sql3) or die(mysql_error());

            echo "<option value=\"0\">" . $row['name'] . "</option>\n";
            while ($row2 = mysql_fetch_assoc($res3)) {
                $selected = ($row2['id'] == $id) ? " SELECTED" : "";
                echo "<option value=\"" . $row2['id'] . "\"" . $selected .
                    ">     " . $row2['name'] . "</option>\n";
            }
        }
        echo "</select></td></tr>\n";
        echo "<tr><td>Listing Title</td><td><input type=\"text\" name=\"title\"></td></tr>\n";
        echo "<tr><td>Message</td><td><textarea id=\"markItUp\" name=\"message\" style=\"width:300px;height:100px;\"></textarea></td></tr>\n";
        echo "<tr><td colspan=\"2\" align=\"right\"><input type=\"submit\" name=\"submit\" value=\"Create Topic\"></td></tr>\n";
        echo "</form></table>\n";
    } else {
        $cat = mss($_POST['cat']);
        $title = mss($_POST['title']);
        $msg = mss($_POST['message']);
	$tags = mss($POST['tags']);

        if ($cat && $title && $msg && $tags) {
            $sql = "SELECT admin FROM `forum_sub_cats` WHERE `id`='" . $cat . "'";
            $res = mysql_query($sql) or die(mysql_error());
            if (mysql_num_rows($res) == 0) {
                echo "This forum sub category does not exist!\n";
            } else {
                $row = mysql_fetch_assoc($res);
                if ($row['admin'] == 1 && $admin_user_level != 1) {
                    echo "You are not an admin therefore you cannot post a new topic on this forum!\n";
                } else {
                    if (strlen($title) < 3 || strlen($title) > 32) {
                        echo "The title must be between 3 and 32 characters!\n";
                    } else {
                        if (strlen($msg) < 3 || strlen($msg) > 10000) {
                            echo "The message must be between 3 and 10,000 characters!\n";
                        } else {
						if (strlen($tags) < 2 || strlen($tags) > 200) {
									echo "You must submit at least 1 tag and no more than a total of 200 characters!\n";
								} else {
                            $date = date("m-d-y") . " at " . date("h:i:s");
                            $time = time();
                            $sql2 = "INSERT INTO `forum_topics` (`cid`,`title`,`uid`,`date`,`time`,`message`,`tags`) VALUES
						('" . $cat . "','" . $title . "','" . $_SESSION['uid'] . "','" . $date . "','" . $time . "','" . $msg . "','" . $tags . "')";
                            $res2 = mysql_query($sql2) or die(mysql_error());
                            $tid = mysql_insert_id();
                            header("Location: index.php?act=topic&id=" . $tid . "");
                        }
                    }
				}
                }
            }
        } else {
            echo "Please supply all the fields!\n";
        }
    }
}
?>

 

It seems to work fine until I put the tags text box in. It works fine however when I submit something it says that I havn't supplied all the fields. I have spent quite a while trying to figure this one out but I am very new to php and understand that it's probably a missing comma or something!

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.