Wrox Programmer Forums
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 26th, 2006, 11:30 PM
Authorized User
 
Join Date: Sep 2006
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default php forum

What is wrong with this code here?
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css">

    body{
        background: #3399FF;
        font-family: Arial;
    }
    td.center{
        text-align: center;
    }
    a{
        text-decoration: none;
        color: black;
        font-family: Arial;
    }
    a:hover{
        color: white;
        text-decoration: underline;
    }
    a:visited{
        color: purple;
    }

</style>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>REDEYEGAMEZ</title>
</head>
<body>
<table width="100%">
  <td width="33%"></td>
    <td width="33%" class="center"><h1>FORUM</h1>
      <p>This is the redeyegamez forum. Here you can discuss different games in more detail, or just the website in general.</p></td>
    <td width="33%"></td>
</table>
<?php    
    function displaytopics($forum_id, $link_target){
        echo "\n\n";

        if ( ! ( $con = mysql_connect("connect""username","password") ))
            die( "<br>Oy vey!  Failed mysql_connect( ) call in function displaytopics( ) with: " . mysql_error( ) . "<br>" );

        if (!mysql_select_db("redeyegamezforum", $con))
            die("<br>Failed to select database: " . mysql_error( ) . "<br>");

        $sql = "SELECT * FROM topic WHERE parent_forum = '$forum_id'";

        if(!$result = mysql_query($sql, $con)){
            die( "<br>Error querying mySQL database.<br>") ;
        }

        if ( mysql_num_rows( $result ) == 0 ) 
            die( "<br />Query returned no results in function displaytopics( ).  Goodbye!<br />" );

        while($topic = mysql_fetch_assoc($result)){
            echo "<tr>";
            echo "<td class='topicfiller' colspan='2'>$nbsp;</td>";
            echo "<td class='topiclink'>";
            echo '<a href="' . $link_target . '?topicid =' . $topic['id'] . '">';
            echo $topic['name'] . "</a></td>";
            echo "<td class='topicdesc'>" . $topic['description'] . "</td></tr><br />";
        } // end while( mysql_fetch_assoc( ) )

    } // end function displaytopics( )

    $con = mysql_connect("connect","username","password");

    if(!$con){
        die("error connnecting to forums database.");
    }

    if ( ! mysql_select_db("redeyegamezforum", $con) )
        die( mysql_error( ) );

    $sql = "CREATE TABLE forums(
                id INTEGER UNSIGNED NOT NULL auto_increment,
                name VARCHAR(100) NOT NULL,
                description TEXT NOT NULL,
                PRIMARY KEY(id)
            )";
    mysql_query($sql, $con);

    $sql = "CREATE TABLE topic(
                parent_forum INTEGER UNSIGNED NOT NULL,
                id INTEGER UNSIGNED NOT NULL auto_increment,
                name VARCHAR(100),
                description TEXT NOT NULL,
                PRIMARY KEY(id)
            )";
    mysql_query($sql, $con);

    $sql = "CREATE TABLE thread(
                parent_topic INTEGER UNSIGNED NOT NULL,
                id INTEGER UNSIGNED NOT NULL auto_increment,
                subject TEXT NOT NULL,
                replies INTEGER UNSIGNED,
                last_post TIMESTAMP,
                PRIMARY KEY(id)
            )";
    mysql_query($sql, $con);


    $sql = "CREATE TABLE post(
                parent_topic INTEGER UNSIGNED NOT NULL,
                id INTEGER UNSIGNED NOT NULL auto_increment,
                author VARCHAR(100) NOT NULL,
                body TEXT,
                in_reply_to INTEGER UNSIGNED,
                date TIMESTAMP,
                PRIMARY KEY(id)
            )";

    mysql_query($sql, $con);

    $sql = "SELECT * FROM forums WHERE name = 'REDEYEGAMEZ'";
    if ( ! ( $result = mysql_query($sql, $con) ) )
        die( "<br>" . mysql_error( ) . "<br> ");

    if ( ! ( $row = mysql_fetch_assoc($result) ) )
        die( "<br>" . mysql_error( ) . "<br> ");

    if($row['name'] != "REDEYEGAMEZ"){
        $sql = "INSERT INTO forums(name, description) VALUES('REDEYEGAMEZ','General talk about redeyegamez')";
        mysql_query($sql, $con);
    }



    $sql = "SELECT * FROM topic WHERE name = 'Rants'";

    if(!($result = mysql_query($sql, $con)))
        die("<br />" . mysql_error($con) . "<br />");

    if (!($row = mysql_fetch_assoc($result)))
        die("<br />" . mysql_error($con) . "<br />");

    if($row['name'] != "Rants"){
        $sql = "INSERT INTO topic(parent_forum, name, description) VALUES(1, 'Rants', 'Things you don't like about our site.')";
        mysql_query($sql, $con);
    }



    $sql = "SELECT * FROM forums";
    if ( ! ( $result = mysql_query($sql, $con) ) )
        die( "<br>" . mysql_error( ) . "<br> ");


    if ( mysql_num_rows( $result ) == 0 )
        die( "<br>Query '" . $sql . "' returned zero rows.<br>" );

    echo "<table width='100%' class='forumline' cellpadding='4' cellspacing='2' border='0' align='center'>\n";
    echo "<tbody>";

    while($forum = mysql_fetch_assoc($result)) {
        echo "\n\n";
        echo "\n<tr>";
        echo "<td class='forumtitle' colspan='5'>";
        echo $forum['name'];
        if ( ! isset( $forum[ 'id' ] ) )
            die( "\n\n" );
        displaytopics($forum['id'], "topic.php");

    }
?>
</body>
</html>
Nothing is desplaying except for the "FORUM, blah blah blah blah".

"Judge a man by his questions, not by his answers."
-Voltaire
__________________
\"Judge a man by his questions, not by his answers.\"
-Voltaire
 
Old November 28th, 2006, 10:19 PM
Authorized User
 
Join Date: Sep 2006
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Alright, I found the problem. When I was checking the return value of "mysql_fetch_assoc()", it will return false if $result has no rows, so there you go. My code was dying for no reason, which explains why no mysql_error came up.

"Judge a man by his questions, not by his answers."
-Voltaire
 
Old December 21st, 2006, 06:04 AM
Authorized User
 
Join Date: Dec 2006
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to paagle
Default

isnt there any way to remove this topic?
It is solved and makes no sense being here

---
Paagle
TEAM LEADER-Team Xuberance(http://www.xuberance.com)
 
Old January 22nd, 2011, 02:03 AM
Registered User
 
Join Date: Jan 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Orissajobs.info

PHP often works alongside MySQL in creating a very dynamic website. Both of these languages are open source too so you do not have to worry about costly licensing issues. It also integrates with HTML so you can apply any existing knowledge of HTML to your PHP content.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Constructing a Forum using PHP Giri PHP How-To 4 September 30th, 2011 03:07 PM
Forum admin.php LCMatt PHP How-To 0 March 18th, 2006 06:27 PM
How can I creat a forum like P2P Forum? pcassiano ASP.NET 1.0 and 1.1 Basics 1 October 31st, 2005 05:00 AM
Forum expanded to Beginning PHP 5 jminatel BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 2 November 2nd, 2004 03:14 AM
converting Forum.aspx to Forum.ascx (help) drfunkie BOOK: ASP.NET Website Programming Problem-Design-Solution 1 July 11th, 2003 12:27 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.