Jump to content

Archived

This topic is now archived and is closed to further replies.

Birdman203

help with php + mysql

Recommended Posts

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

[code]
<?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;

}

?>
[/code]

line 52 is
[code]
$auto_row = mysql_fetch_assoc($query_auto);
[/code]

Share this post


Link to post
Share on other sites
Maybe your query failed?  Add this line

[code]if ($query_auto === false) die("Query $sql_auto failed\n");[/code]

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.

Share this post


Link to post
Share on other sites
There is an error in your SHOW TABLE STATUS command. See MYSql doc: the syntax is:

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

So you must alter your statement to something like:

[code]$sql_auto = "SHOW TABLE STATUS LIKE '" . POSTS_TABLE . "'";[/code]

Ronald  8)

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.