| View previous topic :: View next topic |
| Author |
Message |
deleted user 111213 Grandmaster Cheater
Reputation: 0
Joined: 09 Nov 2007 Posts: 714
|
Posted: Sun Nov 30, 2008 2:51 pm Post subject: cant seem to get my forums to work. |
|
|
here is my forum-index.php
| Code: | <?php
session_start();
include'./global.php';
$action = $_GET['act'];
$actions_array = array('forum');
?>
<html>
<head>
<title>Nostrich's Forum</title>
<link rel="stylesheet" href="./style3.css" type="text/css" />
</head>
<body>
<center>
<div id="holder">
<div id="userInfo">
<?php
if($_SESSION['uid']){
$sql = "SELECT * FROM users WHERE id = '" . $_SESSION['uid'] . "'";
$res = mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($res) == 0){
session_destroy();
echo "Please <a href='login2.php'>Login</a> to your account, or <a href='reg.php'>Register</a> a new account!\n";
}else{
$row = mysql_fetch_assoc($res);
echo "Welcome back,<a href=\"./forum-index.php?act=profile&id=".$row['id']."\">".$row['username']."</a>! <a href=\"./logout.php\">Logout</a>\n";
echo "<br>\n";
echo " <a href=\"./forum-index.php\">Forum Index</a>\n";
if($row['admin'] == '1'){
echo " | <a href=\"./admin.php\">Adminastrators section</a>\n";
}
}
}else{
echo "Please <a href='login2.php'>Login</a> to your account, or <a href='reg.php'>Register</a> a new account!\n";
}
?>
</div>
<div id="content">
<?php
if(!$action || !in_array($action,$actions_array)){
$sql1 = "SELECT * FROM forum_cats WHERE admin < ".$row['admin']. "+1";
$res1 = mysql_query($sql1) or die(mysql_error());
$i=1;
while ($row2 = mysql_fetch_assoc($res1)){
echo "<div id='fcontent'>\n";
echo "<div class='header' id=\"header_".$i."\" onMouseOver=\"this.className='headerb'\" onMouseOut=\"this.className='header'\">".$row2['name']."</div>\n";
$sql2 = "SELECT * FROM forum_sub_cats WHERE cid='".$row2['id']."' AND admin < ".$row['admin']."+1";
$res2 = mysql_query($sql2) or die(mysql_error());
while($row3 = mysql_fetch_assoc($res2)){
echo "<div id='content'>\n";
echo "<a href=\"./forum-index.php?act=forum&id=".$row3['id']."\">".$row3['name']."</a><br>\n";
echo " " .$row3['desc'] . "\n";
echo "</div>\n";
}
echo "</div>\n";
$i++;
}
}else{
if($action == 'forum'){
include "./includes/forum.php";
}
}
?>
</div>
</div>
</center>
</body>
</html> |
and forum.php in the includes folder!
| Code: | <?php
$id = mss($_GET['id']);
if($id){
$sql = "SELECT * FROM forum_cats WHERE id='".$id."'";
$res = mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($res) == 0){
echo "The forum category you supplied does not exist!\n";
}
}
?> |
but i have a few forums which do exist but it tells me that they dont!
what should i do????????
|
|
| Back to top |
|
 |
sloppy Expert Cheater
Reputation: 0
Joined: 17 Aug 2008 Posts: 123
|
Posted: Sun Nov 30, 2008 8:29 pm Post subject: |
|
|
I created a test page using your code which you can view here -> http://cef.coolpage.biz/ghostrider.php?id=1. My table only has 3 entries, so try id=2, id=3, id=4 and so on.. to see the results.
ghostrider.php
| Code: | <html>
<head>
<title>Hello</title>
</head>
<body>
<?php
include "mysql_connect.php";
// global.php
function mss($value)
{
return mysql_real_escape_string(trim(strip_tags($value)));
}
// forum.php
$id = mss($_GET['id']);
if($id)
{
$sql = "SELECT * FROM forum_cats WHERE id='".$id."'";
$res = mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($res) == 0)
{
echo "The forum category you supplied does not exist!\n";
}
else
{
echo "<table border=\"1\"><tr><th>Id</th><th>Category</th><th>Description</th></tr>";
while($row = mysql_fetch_assoc($res))
{
echo "<tr><td>$row[id]</td><td>$row[cat]</td><td>$row[desc]</td></tr>";
}
echo "</table>";
}
}
mysql_close();
?>
</body>
</html> |
I've added an else statement to show the db results on success, but other than that it's your (ugly ) code and works as expected?.. it's possible that your id's are mismatched with those of the table column id. I noticed in some of your sql queries you use "WHERE cid = .." instead of id?
Manually check your id variable against the id's in your table using phpMyAdmin to see if it points to the correct category.
|
|
| Back to top |
|
 |
deleted user 111213 Grandmaster Cheater
Reputation: 0
Joined: 09 Nov 2007 Posts: 714
|
Posted: Mon Dec 01, 2008 10:11 am Post subject: |
|
|
thanks, this works now. u rock big time.
EDIT: I cant seem to get this echo to appear. BTW, i got rid of the table because i felt no nood for it.
this is forum.php now
| Code: | <?php
$id = $_GET['id'];
if($id)
{
$sql = "SELECT * FROM `forum_cats` WHERE `id`='".$id."'";
$res = mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($res) == 0)
{
echo "The forum category you supplied does not exist!\n";
}
else{
$row = mysql_fetch_assoc($res);
if($row['admin'] == 1 && $admin_user_level == 0){
echo "You must be an admin to view this forum!\n";
}else{
$sql2 = "SELECT * FROM `forum_topics` WHERE `cid`='".$row['id']."'";
$res2 = mysql_query($sql2) or die mysql_error());
if(mysql_num_rows($res2) == 0){
echo "There are no topics in this forum, <a href=\"./forum-index.php?act=create&id=".$row['id']."\">click here</a> to create a topic!\n";
}
}
}
}
?> |
the line that i'm having trouble with now is
| Code: | | echo "There are no topics in this forum, <a href=\"./forum-index.php?act=create&id=".$row['id']."\">click here</a> to create a topic!\n"; |
|
|
| Back to top |
|
 |
sloppy Expert Cheater
Reputation: 0
Joined: 17 Aug 2008 Posts: 123
|
Posted: Mon Dec 01, 2008 11:19 am Post subject: |
|
|
| Code: | | echo "There are no topics in this forum, <a href=\"/forum-index.php?act=create&id=$row[id]\">click here</a> to create a topic!\n"; |
|
|
| Back to top |
|
 |
Reak I post too much
Reputation: 0
Joined: 15 May 2007 Posts: 3496
|
Posted: Mon Dec 01, 2008 11:23 am Post subject: |
|
|
or
| Code: | | echo 'There are no topics in this forum, <a href="/forum-index.php?act=create&id=$row[id]">click here</a> to create a topic!\n'; |
|
|
| Back to top |
|
 |
deleted user 111213 Grandmaster Cheater
Reputation: 0
Joined: 09 Nov 2007 Posts: 714
|
Posted: Mon Dec 01, 2008 11:24 am Post subject: |
|
|
still didn't work. maybe it's something else in the code?
none of them work!
|
|
| Back to top |
|
 |
Reak I post too much
Reputation: 0
Joined: 15 May 2007 Posts: 3496
|
Posted: Mon Dec 01, 2008 11:39 am Post subject: |
|
|
hmm try this:
| Code: | <?php
function isInteger($input){
return preg_match('@^[-]?[0-9]+$@',$input) === 1;
}
function ShowTopics($forumid){
$sql = "SELECT * FROM `forum_topics` WHERE `cid`=$forumid";
$res = mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($res) == 0){
echo 'There are no topics in this forum, <a href="/forum-index.php?act=create&id=$row[id]">click here</a> to create a topic!\n';
} else {
echo "forum..<br />";
}
}
$id = $_GET['id'];
if(isInteger($id)){
$sql = "SELECT * FROM `forum_cats` WHERE `id`=$id";
$res = mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($res) == 0){
echo "The forum category you supplied does not exist!\n";
} else {
$row = mysql_fetch_assoc($res);
if($row['admin'] > 0){
if($admin_user_level > 0){
ShowTopics($row['id']);
} else {
echo "You must be an admin to view this forum!\n";
}
} else {
ShowTopics($row['id']);
}
}
}
?>
|
Note: I edited a bit so it's more secure from SQL-injection.
Tell me if it works.
|
|
| Back to top |
|
 |
deleted user 111213 Grandmaster Cheater
Reputation: 0
Joined: 09 Nov 2007 Posts: 714
|
Posted: Mon Dec 01, 2008 12:35 pm Post subject: |
|
|
thanks, that worked. but i'm just going to finish create.php But now it says some of them don't exist again. and also i'm having even more trouble. i'm trying to make a drop down box of where the user wants to post, but it doesn't show up as well as the id of the post.
create.php code
| Code: | <?php
$id = $_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 doesn't exist!\n";
}else{
$row1 = mysql_fetch_assoc($res);
if($row1['admin'] == 1 && $admin_user_level == 0){
echo "You are not an admin, you ,cannot post here!\n";
}else{
echo "<table border='0' cellspacing='3' cellpadding='3'>\n";
echo "<form method='post' action='forum-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 id='".$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";
}
}
}
?> |
|
|
| Back to top |
|
 |
|