hi guys working on a little basic forum for collage but i keep getting this error kinda driving me crazy i know its something small but i cant spot it. any help would be great

Notice: Undefined index: topic_id in /users/2014/daf1/public_html/cs1109/lab18/showit.php on line 14

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /users/2014/daf1/public_html/cs1109/lab18/showit.php on line 23

<?php

  require_once( 'output_functions.php' );
    require_once( 'validation_functions.php' );
    require_once( 'database_functions.php' );
    $dbconnection = connect_to_database( 'localhost', 'daf1', 'PASSCODE', '2013?daf1' );
    output_header( 'reveiwers nation', 'rr.css' );
   
	




$verify_topic = "SELECT topic_title FROM forum_topics WHERE topic_id = '".$_GET["topic_id"]."'";
$dbinsert_result = mysql_query($verify_topic);
  if ( ! $dbinsert_result )
            {
                output_problem_page();
                mysql_close( $dbconnection );
                die();
            }

if (mysql_num_rows($verify_topic) < 1) {
	//this topic does not exist
	$display_block = "<p><em>You have selected an invalid topic.<br/>
	Please <a href=\"topiclist.php\">try again</a>.</em></p>";
} else {
	//get the topic title
	while ($topic_info = mysql_fetch_array($verify_topic_res)) {
		$topic_title = $topic_info['topic_title'];
	}

	//gather the posts
	$get_posts = "SELECT post_id, post_text, DATE_FORMAT(post_create_time, '%b %e %Y at %r') AS fmt_post_create_time, post_owner FROM forum_posts WHERE topic_id = '".$_GET["topic_id"]."' ORDER BY post_create_time ASC";
	$dbinsert_result = mysql_query($dbconnection, $get_posts);
  if ( ! $dbinsert_result )
            {
                output_problem_page();
                mysql_close( $dbconnection );
                die();
            }

	//create the display string
	$display_block = "
	<p>Showing posts for the <strong>".$topic_title."</strong> topic:</p>
	<table>
	<tr>
	<th>AUTHOR</th>
	<th>POST</th>
	</tr>";

	while ($posts_info = mysql_fetch_array($get_posts)) {
		$post_id = $posts_info['post_id'];
		$post_text = $posts_info['post_text'];
		$post_create_time = $posts_info['fmt_post_create_time'];
		$post_owner = $posts_info['post_owner'];

		//add to display
	 	$display_block .= "
		<tr>
		<td>".$post_owner."<br/>[".$post_create_time."]</td>
		<td>".$post_text."<br/><br/>
		<a href=\"replytopost.php?post_id=".$post_id."\"><strong>REPLY TO POST</strong></a></td>
		</tr>";
	}

	//free results
	mysql_free_result($get_posts);
	mysql_free_result($verify_topic);

	//close connection to MySQL
mysql_close($dbconnection);

	//close up the table
	$display_block .= "</table>";
}
?>

Recommended Answers

All 6 Replies

1. Check if topic_id is set. Execute the query only if it is set.
2.

$topic_info = mysql_fetch_array($verify_topic_res) [line 29]

Where did $verify_topic_res come from?

Hope this helps.

aha i had a different name for it before

cheers

no im still getting those errors
um heres one of mysql database i made that im using

topic_id INT NOT NULL PRIMARY KEY AUTO_INCREMENT
topic_title VARCHAR NOT NULL ()150
topic_create_time DATETIME NOT NULL
topic_owner VARCHAR NOT NULL (150)
if (!isset($_GET["topic_id"])){
              output_header()
                      exit;}

i think that solves the 1st error

Is it exactly the same error as before. Also, one I missed the first time.

if (mysql_num_rows($verify_topic) < 1)[line 23]
//$verify_topic is a string. Not a mysql result set.

Hope this helps.

cheer ya got it working now thanks for the help

These errros though small can cause a trouble for solving them if not identified correctly. Make sure you have the database tables and columns used in the query in a right way. Best Wishes!

Regards,
SibzSolutions

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.