Jump to content

php forum


Recommended Posts

Why is this code not working? It should display the forums and their topics, but instead one of the "die()" functions executes, and I do not know why.

<!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<!-- In function displaytopics( '$forum_id', '$link_target' ); -->\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<!-- in the while( ) loop! -->\n";		echo "\n<tr>";		echo "<td class='forumtitle' colspan='5'>";		echo $forum['name'];		if ( ! isset( $forum[ 'id' ] ) )			die( "\n<!-- couldn't find ID for this forum -->\n" );		displaytopics($forum['id'], "topic.php");	}?></body></html>

Link to post
Share on other sites

It dies at the point where it does:

 $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);	}

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...