LooieENG Posted August 30, 2008 Share Posted August 30, 2008 <?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 Link to comment https://forums.phpfreaks.com/topic/122013-not-adding-to-the-database-and-doing-what-i-expect/ Share on other sites More sharing options...
Vermillion Posted August 30, 2008 Share Posted August 30, 2008 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'"); ?> Link to comment https://forums.phpfreaks.com/topic/122013-not-adding-to-the-database-and-doing-what-i-expect/#findComment-629803 Share on other sites More sharing options...
DarkWater Posted August 30, 2008 Share Posted August 30, 2008 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. Link to comment https://forums.phpfreaks.com/topic/122013-not-adding-to-the-database-and-doing-what-i-expect/#findComment-629807 Share on other sites More sharing options...
waynew Posted August 30, 2008 Share Posted August 30, 2008 Both ways work. Also, I'd mysql_real_escape_string() that sh*t if I were you. Link to comment https://forums.phpfreaks.com/topic/122013-not-adding-to-the-database-and-doing-what-i-expect/#findComment-629819 Share on other sites More sharing options...
LooieENG Posted August 30, 2008 Author Share Posted August 30, 2008 Thanks for the suggestions, anyone know how I can fix the script though? Thanks Link to comment https://forums.phpfreaks.com/topic/122013-not-adding-to-the-database-and-doing-what-i-expect/#findComment-629874 Share on other sites More sharing options...
LooieENG Posted August 31, 2008 Author Share Posted August 31, 2008 Anyone? :/ Link to comment https://forums.phpfreaks.com/topic/122013-not-adding-to-the-database-and-doing-what-i-expect/#findComment-630355 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.