Discussion Forums error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ryuzaki
    New Member
    • Jan 2008
    • 6

    Discussion Forums error

    Hi I am new to the forums and I have one question I read through this tutorial:

    Tutorial

    and I get this error when I view the index.php3 file

    Code:
    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/[I]user[/I]/public_html/forum/index.php3 on line 36
    
    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/[I]user[/I]/public_html/forum/index.php3 on line 51
  • prabapraba
    New Member
    • Jan 2008
    • 4

    #2
    Your query have some problems..
    Your query is not executed ...

    Comment

    • ryuzaki
      New Member
      • Jan 2008
      • 6

      #3
      Would you by happen to know the general issue behind query's not being executed?
      In my previous post the code written says that there is an issue on line 36. This is what the piece of code is on line 36.
      Code:
      	while ($topic = mysql_fetch_array($topic_query)) {
      This line is from this piece of code:
      Code:
      <?php
      $topic_query = mysql_query("SELECT * FROM topics ORDER BY ID");
      	while ($topic = mysql_fetch_array($topic_query)) {
      ?>
      Thanks for the reply.

      Comment

      • ryuzaki
        New Member
        • Jan 2008
        • 6

        #4
        Bump, please can someone help me. Thanks

        Comment

        • Markus
          Recognized Expert Expert
          • Jun 2007
          • 6092

          #5
          Please post the rest of that code.

          Thanks.

          Comment

          • ryuzaki
            New Member
            • Jan 2008
            • 6

            #6
            Code:
            <?php
            require( './functions.php3');
            
            showheader("Here are your Topics");
            ?>
            
            <TABLE BORDER=0 WIDTH=100% CELLSPACING=3 CELLPADDING=5>
            	<TR>
            		<TD>
            		<FONT COLOR="#000000" FACE="Arial,Verdana,Helvetica" size=-1>
            		<b>Topics: </b>
            		<BR>
            		<P>
            		<a href="add-topic.php3"><FONT COLOR="#000000">Make a Topic</a>
            		</TD>
            	</TR>
            </TABLE>
            <P>
            <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=100%>
            	<TR VALIGN=TOP ALIGN=LEFT>
            		<TD WIDTH=100%>
            			<TABLE BORDER=0 BGCOLOR="#000000" CELLSPACING=1 CELLPADDING=1 WIDTH=100%>
            				<TR>
            					<TD BGCOLOR="#C0C0C0" WIDTH=100%>
            						<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=5 WIDTH=100%>
            							<TR>
            								<TD>
            								<P><B><FONT COLOR="#000000" FACE="Trebuchet MS,Arial,Helvetica">Topics</FONT></B>
            								</TD>
            							</TR>
            						</TABLE>
            					</TD>
            				</TR>
            <?php
            $topic_query = mysql_query("SELECT * FROM topics ORDER BY ID");
            	while ($topic = mysql_fetch_array($topic_query)) {
            ?>
            	<TR>
            	<TD WIDTH=82% BGCOLOR="#FFFFFF" HEIGHT=28 VALIGN=TOP>
            		<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=5 WIDTH=100%>
            			<TR>
            				<TD>
            				<P><FONT SIZE="+1" FACE="Trebuchet MS,Arial,Helvetica"><a href="view.php3?topicID=<?php echo $topic['ID'] ?>"><?php echo $topic['TopicName'] ?></a></FONT> 
            				</TD>
            			</TR>
            		</TABLE>
            	</TD>
            </TR>
            <?php
            } 
            if (mysql_num_rows($topic_query) < 1) {
            ?>
            <TR height=300>
            	<TD WIDTH=100% BGCOLOR="#FFFFFF" HEIGHT=28 VALIGN=TOP>
            	<CENTER><FONT SIZE="-1" FACE="Trebuchet MS,Arial,Helvetica">
            	<BR><B>There Are No Topics</B><BR><BR></CENTER>
            	</TD>
            </TR>
            <?php } ?>
            </TABLE>
            </TD></TR>
            </TABLE>
            <?php
            showfooter();
            ?>

            Comment

            • stepterr
              New Member
              • Nov 2007
              • 157

              #7
              Text Case is very important in PHP and SQL. So I would make sure that you have the table and fieldname the exact same way they appear in your database.

              Comment

              • ryuzaki
                New Member
                • Jan 2008
                • 6

                #8
                ahh I think i seem to have found the issue. It seems the tables for the database are not being created.

                When I put this into the mySQL query to create the tables:
                Code:
                 CREATE TABLE posts (
                   ID int(5) DEFAULT '0' NOT NULL auto_increment,
                   TopicID int(5) DEFAULT '0' NOT NULL,
                   Name varchar(50) NOT NULL,
                   Email varchar(50) NOT NULL,
                   Password varchar(50) NOT NULL,
                   TimeStamp varchar(10) NOT NULL,
                   Post text NOT NULL,
                   PRIMARY KEY (ID)
                );
                
                CREATE TABLE topics (
                   ID int(5) DEFAULT '0' NOT NULL auto_increment,
                   TopicName varchar(50) NOT NULL,
                   PRIMARY KEY (ID)
                );
                I get this error returned from phpMyAdmin:
                Code:
                Error
                
                SQL query:
                
                CREATE TABLE posts(
                ID int( 5 ) DEFAULT '0' NOT NULL AUTO_INCREMENT ,
                TopicID int( 5 ) DEFAULT '0' NOT NULL ,
                Name varchar( 50 ) NOT NULL ,
                Email varchar( 50 ) NOT NULL ,
                PASSWORD varchar( 50 ) NOT NULL ,
                TimeStamp varchar( 10 ) NOT NULL ,
                Post text NOT NULL ,
                PRIMARY KEY ( ID )
                );
                
                MySQL said: Documentation
                #1067 - Invalid default value for 'ID'
                What does this mean?

                Comment

                • ryuzaki
                  New Member
                  • Jan 2008
                  • 6

                  #9
                  never mind I got around this issue by manually creating the tables, but now a new problem has arised, I cant seem to post anything. After i submit an article it will just seem like the page reloaded and all the fields are empty again. Whats going on here?

                  Comment

                  • stepterr
                    New Member
                    • Nov 2007
                    • 157

                    #10
                    What does your form tag look like? If you are posting back to the same page and not assigning your fields the posted values that is probably why it would be blanking out.

                    Comment

                    Working...