Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old November 26th, 2006, 10:30 PM
Authorized User
 
Join Date: Sep 2006
Location: , , .
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
Reply With Quote
  #2 (permalink)  
Old November 28th, 2006, 09:19 PM
Authorized User
 
Join Date: Sep 2006
Location: , , .
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
Reply With Quote
  #3 (permalink)  
Old December 21st, 2006, 05:04 AM
Authorized User
 
Join Date: Dec 2006
Location: Burla, Orissa, India.
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)
Reply With Quote
  #4 (permalink)  
Old January 22nd, 2011, 01: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.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 05:27 PM
How can I creat a forum like P2P Forum? pcassiano ASP.NET 1.0 and 1.1 Basics 1 October 31st, 2005 04: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 02: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



All times are GMT -4. The time now is 05:05 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.