Syntax error with mysql query.

[ul]Sorry if this is a dumb question, but I have adapted a forum post query code in hopes to have all new forum posts appear on my homepage. This code appears to be connecting to the mysql server and database properly but is not fetching data properly. I receive the following code from using “mysql_error()”…"Parse error: syntax error, unexpected T_WHILE in C:\wamp\www\index.php on line 88>

Im currently using wamp server with FluxBB running
MYSQL Version: 5.5.24
PHP (with phpMyAdmin) Version: 5.5.13

This is more likely due to improper PHP version but here is the code anyway. Hopefully someone can help me!

[php] <?php

	$db = mysql_connect("localhost", "*****", "*********");

mysql_select_db(“forum”,$db);

$result = mysql_query(“SELECT * FROM Requests”,$db);

$server = ‘localhost’; // server location
$user = ‘’; // db username
$password = '
****’; // db password
$db = ‘forum’; // db name

$link = mysql_connect("$server", “$user”, “$password”);
mysql_select_db("$db");

//
//

$query = “select destinct t.topics_id, t.topic_title
from posts p, topics t
where p.topic_id = t.topic_id
order by p.post_time desc
limit 10”;
$result = mysql_query($query);

//
//

print “

    ”;

    while ($row = mysql_fetch_assoc($result)) {
    $topic_id = $row[‘topic_id’];
    $topic_title = $row[‘topic_title’];
    print “[*]<a href=/forum/viewtopic.php?t=$topic_id”>$topic_title";
    }
    print "[/ul]
    ";

    ?>[/php]

    Thanks in advance.

It means your query isn’t working. add or die(mysql_error()); to the end of your query.

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\wamp\www\index.php on line 83
Call Stack

Time Memory Function Location

1 0.0004 680616 {main}( ) …\index.php:0
2 0.0115 688688 mysql_fetch_assoc ( ) …\index.php:83

This is what i recieve on my index page now after adding, and i get the same when i remove mysql_error();

yea, you’re query is failing. from the look of your code, you have multiple connections going out to the server. you only need 1

either take out
$db = mysql_connect(“localhost”, “", "****”);
mysql_select_db(“forum”,$db);

or take out
$server = ‘localhost’; // server location
$user = ‘’; // db username
$password = '
****’; // db password
$db = ‘forum’; // db name

$link = mysql_connect("$server", “$user”, “$password”);
mysql_select_db("$db");

Tried the code both ways, still getting the same mysql_fetch_assoc() error.

here is the full code

<html>
<head>
<title>ArcheAgeAddicts.com</title>
<!--[if IE]><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
<link rel="stylesheet" type="text/css" href="style.css" />
<style type="text/css">
body {
	background-image: url(images/wallpaper.jpg);
	background-repeat: no-repeat;
}
</style>
<link href="SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css">
<meta charset="utf-8">
<script src="SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
</head>
<body>

    <div id="wrapper">
        <div id="headerwrap">
        <div id="header">
        <div id="headerlogowrap">
        <div id="headerlogo">
        </div>
        </div>
        <div id="navigationwrap">
        <div id="navigation">
          <ul id="MenuBar1" class="MenuBarHorizontal">
              <li>Home</li>
              
              <li>
              <ul>
                  <li><a href="../forum/index.php">Forums</a></li>
                  <li><a href="#">News</a></li>
                </ul>
              Community</li>
              <li>
              <ul>
                  <li><a href="#">Character Guides</a></li>
                  <li><a href="#">Game Guides</a></li>
                </ul>
              Guides</li>
              <li class="MenuBarItemHover">
              <ul>
                  <li><a href="#">Fansite Kit</a></li>
                  <li><a href="#">Screen Shots</a></li>
                  <li><a href="#">Videos</a></li>
                  <li><a href="#">Helpful Tools</a></li>
              </ul>
              Downloads</li>
            </ul>
			</div>
           	 </div>
                  <div id="sidebarwrap">
        <div id="sidebar">
      <?php

$server = 'localhost';  // server location
$user = 'admin';     // db username
$password = 'Maynard12';   // db password
$db = 'forum';  // db name

$link = mysql_connect("$server", "$user", "$password");
mysql_select_db("$db");
//
//
$query = "select destinct t.topics_id, t.topic_title
        from posts p, topics t
        where p.topic_id = t.topic_id
        order by p.post_time desc
        limit 10";
$result = mysql_query($query);
//
//
print "<ul>";

while ($row = mysql_fetch_assoc($result)) {
        $topic_id = $row['topic_id'];
        $topic_title = $row['topic_title'];
        print "[*]<a href=/forum/viewtopic.php?t=$topic_id\">$topic_title</a>";
}
print "[/list]";

?>

        </div>
        </div>
        
        <div id="contentwrap">
        <div id="content">
        <p><strong>Archage Addicts launches!</strong></p>
        </div>
        </div>
        <div id="footerwrap">
        <div id="footer">
            <p>©AddictedDesigns 2012-2013. All rights to content reserved to AddictedDesigns. Some images on this website obtained from XLGAMES.</p>
        </div>
        </div>
    </div>
<script type="text/javascript">
var MenuBar1 = new Spry.Widget.MenuBar("MenuBar1", {imgDown:"SpryAssets/SpryMenuBarDownHover.gif", imgRight:"SpryAssets/SpryMenuBarRightHover.gif"});
        </script>
</body>
</html>

The database stuff is wrong, you don’t need quotes around the variables.

Should be:
mysql_connect($server, $user, $password);
mysql_select_db($db);

Sponsor our Newsletter | Privacy Policy | Terms of Service