Problem with index.php

For the discussion of Perl, Python, Ruby, and PHP and other interpreted languages.

Problem with index.php

Post by Zelth on Fri Oct 17, 2008 4:33 pm
([msg=13866]see Problem with index.php[/msg])

I'm creating a discussion forums site (from Practical PHP and MySQL) but when I check out the index.php site on a browser, I get the error : Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\forums\index.php on line 10

I rechecked the code, but I can't seem to find anything wrong with it. Any help?

Here's the config.php file :
Code: Select all
<?php

$dbhost = "localhost";
$dbuser = "root";
$dbpassword = "";
$dbdatebase = "forum";

//Add the name of the forums below
$config_forumsname = "CineForums";

//Add your name below
$config_admin = "Jono Bacon";
$config_adminemail = "jono AT jonobacon DOT org";

//Add the location of your forums below
$config_basedir = "http://localhost/forums/";

?>


Then the header.php file :
Code: Select all
<?php

  session_start();
 
  require("config.php");
 
  $db = mysql_connect($dbhost, $dbuser, $dbpassword);
  mysql_select_db($dbdatabase, $db);
 
 
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <title><?php echo $config_forumsname; ?></title>
  <link rel="stylesheet" href="stylesheet.css" type="text/css" />
</head>
<body>
<div id="header">
<h1><?php echo $config_forumsname; ?></h1>
[<a href="index.php">Home</a>]

<?php

if(isset($_SESSION['USERNAME']) == TRUE) {
  echo "[<a href='logout.php'>Logout</a>]";
}
else {
  echo "[<a href='login.php'>Login</a>]";
  echo "[<a href='register.php'>Register</a>]";
}

?>

[<a href="newtopic.php">New Topic</a>]
</div>
<div id="main">


The footer.php file:
Code: Select all
</div>
<div id="footer">
&copy; 2005 <?php echo "<a href='mailto:"
. $config_adminemail . "'>" .$config_admin . "</a>"; ?>

</div>
</body>
</html>


And finally the index.php file:

Code: Select all
<?php

require("header.php");

$catsql = "SELECT * FROM categories";
$catresult = mysql_query($catsql);

echo "<table cellspacing=0>";

while($catrow = mysql_fetch_assoc($catresult)) {
  echo "<tr class='head'><td colspan=2>";
  echo "<strong>" . $catrow['name'] . "</strong></td>";
  echo "<tr>";
 
  $forumsql = "SELECT * FROM forums WHERE cat_id = " . $catrow['id'] . ";";
  $forumresult = mysql_query($forumsql);
  $forumnumrows = mysql_num_rows($forumresult);
  if($forumnumrows == 0) {
    echo "<tr><td>No forums!</td></tr>";
  }
  else {
    while($forumrow = mysql_fetch_assoc($forumresult)) {
     echo "<tr>";
     echo "<td>";
    
     echo "<strong><a href='viewforum.php?id=" . $forumrow['id'] . "'>" . $forumrow['name'] . "</a></strong>";
     echo "<br /><i>" . $forumrow['description'] . "</i>";
     echo "</td>";
     echo "</tr>";
   }
  }
 
}

echo "</table>";

require("footer.php");

?>


And this is the stylesheet.css file that I used:

Code: Select all
body {
  font-family: "trebuchet ms", verdana, sans-serif;
  font-size: 12px;
  line-height: 1.5em;
  color: #333;
  background: #ffffff;
  margin: 0;
  padding: 0;
  text-align: left;
  width: 100%;
}

p {
  margin-top: 10px;
}

a:link {
  text-decoration: none;
  color: #000;
}

a:visited {
  text-decoration: none;
  border-bottom: 1px dotted #369;
  color: #000;
}

a:hover, a:active {
  text-decoration: none;
  border-bottom: 1px solid #036;
  color: #000;
}

img {
  border: 0;
}

#container {
  position: absolute;
  top: 85px;
  left: 0px;
  background: #ffffff;
  margin: 0 auto 0 auto;
  text-align: left;
  width: 100%;
  height: 100%;
}

#menu {
  font-family: "trebuchet ms", verdana, sans-serif;
  font-size: 14px;
  font-weight: bold;
  position: absolute;
  height: 27px;
  top: 60px;
  left: 0px;
  width: 100%;
  padding: 0px;
  color: #000000;
  background-color: #eee
}

#header {
  position: absolute;
  top: 0px;
  left: 0px;
  height: 60px;
  width: 100%;
  background: #333;
  padding-top: 8px;
  text-align: center;
}

#header h1 {
  font-size: 30px;
  text-transform: uppercase;
  letter-spacing: 0.3em;
  color: #fff;
}

#main {
  margin: 75px 15px 15px 0px;
  padding: 15px 15px 15px 15px;
  background: #FFFFFF;
}

#bar {
  float: left;
  width: 200px;
  background: #eee;
  z-index: 1;
  padding: 10px;
  margin-right: 30px;
  height: 100%;
}

#bar h1 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.3em;
}

table {
  border: thin solid #cccccc;
  background: #ffffff;
}

th {
  letter-spacing: 2.5px;
  background: #eeeeeee;
  color: #000000
  text-transform: uppercase;
  text-align: center;
  border-top: thick solid #eeeeee;
  border-bottom: thin solid #cccccc;
}


Any help would be appreciated. :D
Z~Epsilon
Newbie Programmer
Learned: HTML, XHTML, CSS
Learning: PHP, C++
Zelth
Poster
Poster
 
Posts: 149
Joined: Mon Sep 08, 2008 7:45 pm
Blog: View Blog (0)


Re: Problem with index.php

Post by Zelth on Fri Oct 17, 2008 4:49 pm
([msg=13868]see Re: Problem with index.php[/msg])

Oh my goodness... never mind guys, I found out the problem after looking it over again right after posting this. The problem was that I misspelled "$dbdatabase" in the config.php file, and I spelled it as "$dbdatebase" :D

No need to reply to this topic anymore. Thanks all.
Z~Epsilon
Newbie Programmer
Learned: HTML, XHTML, CSS
Learning: PHP, C++
Zelth
Poster
Poster
 
Posts: 149
Joined: Mon Sep 08, 2008 7:45 pm
Blog: View Blog (0)



Return to Interpreted Languages

Who is online

Users browsing this forum: No registered users and 0 guests