Jump to content

Recommended Posts

<?php

require('../config.php');

if (!$_SESSION['id']) {
header('location: ../login.php');
exit;
} else {
$result = mysql_query("SELECT class, username FROM users WHERE id = '$_SESSION[id]'");
$row = mysql_fetch_array($result);
if ($row['class'] != 1) {
	exit('You don\'t have permission to access this page.');
} else {
	if (!$_GET['cat']) {

?>

<h3>Select a Forum Category</h3>

<?php

		$result = mysql_query("SELECT id, title FROM categories ORDER BY id ASC");
		$queries++;
		for ($i = 0; $i < mysql_num_rows($result); $i++) {
			$row = mysql_fetch_array($result);
			echo '<a href="forums.php?cat=' . $row['id'] . '">' . $row['title'] . '</a><br />';
		}
		exit('<p>Page generated in ' . (microtime() - $stime) . ' seconds with ' . $queries . ' MySQL ' . ($queries == 1 ? 'Query' : 'Queries') . '</p>');
	} else {
		if ($_POST['forum'] && $_POST['desc'] && $_POST['submit']) {
			$forum = htmlentities($_POST['forum'], ENT_QUOTES);
			$desc = htmlentities($_POST['desc'], ENT_QUOTES);
			mysql_query("INSERT INTO forums (title, description) VALUES ('$forum', '$desc')");
			$queries++;
			echo '<p>Done.</p><hr />';
		}

?>

Welcome, <?php echo $row['username'] ?>.

<h3>Add a Forum</h3>

<p><form name="forum" method="post" action="forums.php">
<input type="text" name="forum" /><br />
<input type="text" name="desc" /><br />
<input name="submit" type="submit" value="Add Forum" />
</form></p>

<p>Page generated in <?php echo microtime() - $stime ?> seconds with <?php echo $queries . ' MySQL ' . ($queries == 1 ? 'Query' : 'Queries') ?></p>

<?php

	}
}
}

?>

 

It should add it to the database, then say

 

_______________________________________

 

Done.

 

(horizontal line)

<h3>Add a Forum</h3>

 

<p><form name="forum" method="post" action="forums.php">

<input type="text" name="forum" /><br />

<input type="text" name="desc" /><br />

<input name="submit" type="submit" value="Add Forum" />

</form></p>

 

<p>Page generated in <?php echo microtime() - $stime ?> seconds with <?php echo $queries . ' MySQL ' . ($queries == 1 ? 'Query' : 'Queries') ?></p>

 

_______________________________________

 

Thanks.

 

Edit: Here's what happens for adding categories (and should happen for this too), and here's what happens with forums.php (this page)

 

http://files.ehwtf.com/php.mp4

Take a look at your first query:

 

<?php

"SELECT class, username FROM users WHERE id = '$_SESSION[id]'"

?>

 

I have had the experience in which the script doesn't work when you pass a $_SESSION, $_GET, or $_POST variable directly into the query.  Assign the $_SESSION value to a variable:

 

<?php

$id = $_SESSION['id']

$result = mysql_query("SELECT class, username FROM users WHERE id = '$id'");

?>

Vermillion, that's because you probably weren't doing it right. >_<  Correct array variable interpolation goes something like:

 

<?php
$array['test'] = "nothing";
echo "This example is anything but {$array['test']}!";
?>

 

That's how it "should" be done.

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.