Jump to content


Photo

help with php + mysql


  • Please log in to reply
2 replies to this topic

#1 Birdman203

Birdman203
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 10 September 2006 - 04:53 AM

well the script below shows me the mysql_query result is not correct or somethin error and points to line 52

<?php

$_mode = isset($_REQUEST['mode']) ? $_REQUEST['mode'] : 'view';

switch($_mode)
{

	case 'newtopic':

		$page = "Forums :: New Topic";

		$tpl->assign('title', "$board_config[site_name] " . ":: $page");

		$members->start_session($page);

		$f_id = $_GET['f'];

		$sql = "SELECT * FROM " . FORUMS_TABLE . " WHERE forum_id = '$f_id'";

		$query = mysql_query($sql);

		$num = mysql_num_rows($query);

		$row = mysql_fetch_array($query, MYSQL_ASSOC);

		if ( $num == "0" || empty($row['parent_id']) )
		{
			$tpl->assign('message', 'There is no forum with that ID.');
		}
		else
		{
			if ( $members->check_cat_per( $members->get_member_id(), 'forum_new_topic', $f_id ) == "1" )
			{
				if ($_POST['submit'])
				{
					if ( empty($_POST['title']) || empty($_POST['message']) )
					{
						$tpl->assign('message', 'You left the title and/or message blank.');
						$tpl->assign('redirect', 'index.php?s=forums&mode=newtopic&f=' . $f_id);
					}
					else
					{
						$forum_id		= $f_id;
						$poster			= $members->get_profile( $members->get_member_id() );
						$poster_id		= $poster['member_id'];
						$time			= strtotime("now");
						$title			= submit_textbox($_POST['title']);
						$message		= submit_textbox($_POST['message']);

						$sql_auto			= "SHOW TABLE STATUS " . POSTS_TABLE . "";
						$query_auto			= mysql_query($sql_auto);
						$auto_row			= mysql_fetch_assoc($query_auto);
						$post_id			= $auto_row['Auto_increment'];

						$sql_insert_topic	= "INSERT INTO " . TOPICS_TABLE . " (forum_id, poster_id, title, first_poster_id, first_post_id, last_poster_id, last_post_id, last_post_time) VALUES ('$f_id', '$poster_id', '$title', '$poster_id', '$post_id', '$poster_id', '$post_id', '$time')";
						$query_insert_topic	= mysql_query($sql_insert_topic);
						$topic_id			= mysql_insert_id();

						$sql_insert_post	= "INSERT INTO " . POSTS_TABLE . " (topic_id, forum_id, poster_id, message, post_time, number_in_topic) VALUES ('$topic_id', '$f_id', '$poster_id', '$message', '$time', '1')";
						$query_insert_post	= mysql_query($sql_insert_post);

						$num_topics			= $row['num_topics'] + 1;
						$sql_update_forums	= "UPDATE " . FORUMS_TABLE . " SET num_topics = '$num_topics' WHERE forum_id = '$f_id'";
						$sql_update_query	= mysql_query($sql_update_forums);

						$tpl->assign('message', 'You have succesfully made a new topic.');
						$tpl->assign('redirect', 'index.php?s=forums&mode=view_topic&id=' . $topic_id);
					}
				}
				else
				{
					$tpl->assign('form', '1');

					$sql_parent = "SELECT * FROM " . FORUMS_TABLE . " WHERE forum_id = '$row[parent_id]'";

					$query_parent = mysql_query($sql_parent);

					$row_parent = mysql_fetch_array($query_parent);

					$forum_data				= $row_parent;
					$forum_data['child']	= $row;

					$tpl->assign('forum_data', $forum_data);
				}
			}
			else
			{
				$tpl->assign('message', 'You do not have permission to post a topic in this forum.');
				$tpl->assign('redirect', 'index.php?s=forums&mode=view_forum&id=' . $f_id);
			}
		}

		$tpl->display('forums-newtopic.tpl');

	break;

}

?>

line 52 is
$auto_row			= mysql_fetch_assoc($query_auto);


#2 btherl

btherl
  • Staff Alumni
  • Advanced Member
  • 3,893 posts
  • LocationAustralia

Posted 10 September 2006 - 04:57 AM

Maybe your query failed?  Add this line

if ($query_auto === false) die("Query $sql_auto failed\n");

My first guess would be that POSTS_TABLE is not defined, or not correctly defined (or not properly escaped).  But there are many other reasons for query failure.  The die() call above will show you the query contents, which should help you diagnose the problem.

#3 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 10 September 2006 - 10:05 AM

There is an error in your SHOW TABLE STATUS command. See MYSql doc: the syntax is:

SHOW TABLE STATUS [FROM db_name] [LIKE 'pattern']

So you must alter your statement to something like:

$sql_auto			= "SHOW TABLE STATUS LIKE '" . POSTS_TABLE . "'";

Ronald  8)
RTFM is an almost extinct art form, it should be subsidized.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users