Jump to content

[SOLVED] Warning: mysql_fetch_array(): supplied argument is not a valid MySQL


mrterry

Recommended Posts

Hello I am having error with one of my ACP modules and am not really sure when to begin my trouble shooting to fix this problem. The Module is Admin Ideas. It does appear to work and allow admins to communicate and do as it is suppose to BUT. everytime someone adds or deletes an idea it also includes the following error at top of the page.

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/bluestar/public_html/forum/admin/admin_ideas.php on line 94

 

I am not sure if it is a php error or a database table problem ?  If anyone can please offer assistance I would be very greatful. Below is actual php code that is giving me error.

 

Thanks Terry

 

<?php
/***************************************************************************
* admin_ideas.php
* -------------------
* begin : Saturday, Jul 28, 2007
* copyright : (C) 2007 Funender.com
* email : admin@funender.com
*
* $Id:lang_admin_ideas.php,v 1.0.1 2007/07/28 23:24:01 FuNEnD3R Exp $
*
*
***************************************************************************/


define('IN_PHPBB', 1);

if( !empty($setmodules) )
{
$file = append_sid("admin_ideas.$phpEx").'&mode=view';
$module['General']['Admin_Ideas'] = $file;
return;
}

//
// Let's set the root dir for phpBB
//
$phpbb_root_path = "./../";
require($phpbb_root_path . 'extension.inc');
require('./pagestart.' . $phpEx);
require($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_admin_ideas.' . $phpEx);
include($phpbb_root_path . 'includes/functions_selects.'.$phpEx);


$status = array("0" => $lang['pending'],
1 => $lang['testing'],
2 => "<font color=\"green\">".$lang['done']."</font>",
3 => "<font color=\"red\">".$lang['denied']."</font>");

if($_GET["mode"] == "view" || $_POST["mode"] == "view") {

$template->set_filenames(array(
body => "admin/admin_ideas.tpl")
);

$template->assign_vars(array(
ADD_NEW_IDEA => $lang['Add_New_Idea'],
SAVE => $lang['Save'],
TESTING => $lang['Testing'],
COMPLETE => $lang['Complete'],
DENY => $lang['Deny'],
FILTER => $lang['Filter'],
EDIT => $lang['Edit'],
DELETE => $lang['Delete'],
CURRENTLY => $lang['Currently_Working'],
ADDED => $lang['New_Idea_Added'],
WISH => $lang['Do_Not_Wish'],

F_NONE => $lang['Filter_none'],
F_PENDING => $lang['Filter_pending'],
F_TESTING => $lang['Filter_testing'],
F_DONE => $lang['Filter_done'],
F_DENIED => $lang['Filter_denied'],

S_DATE => $lang['Status_Date'],
S_USER => $lang['Status_User'],
S_IDEA => $lang['Status_Idea'],
S_STATUS => $lang['Status_Status'],
S_OPTIONS => $lang['Status_Options'],

B_WRITE => $lang['Admin_Written'],
B_SUBMIT => $lang['Add_Submit'],

U_IDEA_ACTION => append_sid("admin_ideas.$phpEx"),
U_IDEA_ALL => append_sid("?mode=view"),
U_IDEA_ORD1 => append_sid("?mode=view&orderby=0"),
U_IDEA_ORD2 => append_sid("?mode=view&orderby=1"),
U_IDEA_ORD3 => append_sid("?mode=view&orderby=2"),
U_IDEA_ORD4 => append_sid("?mode=view&orderby=3"))
);


$orderby = $_GET[orderby];
if($orderby != '')
{
$res = mysql_query("SELECT * FROM phpbb_newideas WHERE idea_status='$orderby' ORDER BY idea_id DESC");
}
else
{
$res = mysql_query("SELECT * FROM phpbb_newideas ORDER BY idea_status ASC, idea_id DESC");
}

while($row = mysql_fetch_array($res)) {
$resb = mysql_query("SELECT username FROM phpbb_users WHERE user_id = '".$row["user_id"]."'");
$rowb = mysql_fetch_array($resb);

if($row["idea_status"] == 1) {
$opt1 = append_sid("?mode=status&idea_id=".$row["idea_id"]."&status=0");
} else {
$opt1 = append_sid("?mode=status&idea_id=".$row["idea_id"]."&status=1");
}
$vars = array("IDEA_TIME" => date("m/d/Y", $row["idea_time"]),
IDEA_TEXT => nl2br(htmlspecialchars($row["idea_text"], HTML_ENTITIES)),
IDEA_STATUS => $status[$row["idea_status"]],
USER_NAME => htmlspecialchars($rowb["username"], HTML_ENTITIES),

IDEA_OPT1 => $opt1,
IDEA_OPT2 => append_sid("?mode=status&idea_id=".$row["idea_id"]."&status=2"),
IDEA_OPT3 => append_sid("?mode=status&idea_id=".$row["idea_id"]."&status=3"),
IDEA_OPT4 => append_sid("?mode=edit&idea_id=".$row["idea_id"]),
IDEA_OPT5 => append_sid("?mode=del&idea_id=".$row["idea_id"]));
$template->assign_block_vars("idearow", $vars);
}
$template->pparse("body");
}

if($_POST["save_idea"]) {
$idea_text = $_POST["idea_text"];
if(strlen($idea_text) <= 0) {
$message = $lang['Enter_Message'] . "<br /><br /><a href=\"javascript:history.go(-1)\">". sprintf($lang['Click_Here_Go_Back'] . "</a>");
message_die(GENERAL_MESSAGE, $message);
}

$sql = "INSERT INTO phpbb_newideas (idea_text, idea_time, user_id) 
VALUES('".$_POST["idea_text"]."', '".time()."', '".$userdata["user_id"]."')";

if( !$result = $db->sql_query($sql) )
{
message_die(GENERAL_ERROR, "Couldn't insert into idea table", "", __LINE__, __FILE__, $sql);
}

$message = $lang['Idea_Saved'] . "<br /><br /><a href=\"".append_sid("admin_ideas.$phpEx?mode=view")."\">". sprintf($lang['Click_Here_Go_Back'] . "</a>");
message_die(GENERAL_MESSAGE, $message);
}

if($_GET["mode"] == "status") {
$sql = "UPDATE phpbb_newideas SET idea_status = '".$_GET["status"]."' WHERE idea_id = '".$_GET["idea_id"]."'";
if( !$result = $db->sql_query($sql) )
{
message_die(GENERAL_ERROR, "Couldn't update idea table", "", __LINE__, __FILE__, $sql);
}

$message = $lang['Status_Updated'] . "<br /><br /><a href=\"".append_sid("admin_ideas.$phpEx?mode=view")."\">". sprintf($lang['Click_Here_Go_Back'] . "</a>");
message_die(GENERAL_MESSAGE, $message);
}


if($_GET["mode"] == "del") {
$sql = "DELETE FROM phpbb_newideas WHERE idea_id = '".$_GET["idea_id"]."'";
if( !$result = $db->sql_query($sql) )
{
message_die(GENERAL_ERROR, "Couldn't update idea table", "", __LINE__, __FILE__, $sql);
}

$message = $lang['Idea_Deleted'] . "<br /><br /><a href=\"".append_sid("admin_ideas.$phpEx?mode=view")."\">". sprintf($lang['Click_Here_Go_Back'] . "</a>");
message_die(GENERAL_MESSAGE, $message);
}

if($_GET["mode"] == "edit") {
$sql = "SELECT idea_text, idea_id FROM phpbb_newideas WHERE idea_id = '".$_GET["idea_id"]."'";
if( !$result = $db->sql_query($sql) )
{
message_die(GENERAL_ERROR, "Couldn't update idea table", "", __LINE__, __FILE__, $sql);
}

$row = mysql_fetch_array($result);

$template->set_filenames(array(
body => "admin/admin_ideas_edit.tpl")
);

$template->assign_vars(array(
EDIT_IDEA => $lang['Edit_Idea'],
SAVE => $lang['Save'],
IDEA_TEXT => htmlspecialchars($row["idea_text"], HTML_ENTITIES), 
IDEA_ID => $row["idea_id"],

B_WRITE => $lang['Admin_Written'],
B_SUBMIT => $lang['Add_Submit'],

U_IDEA_ACTION => append_sid("admin_ideas.$phpEx"))
);
$template->pparse("body");
}

if($_POST["save_edit_idea"]) {
$sql = "UPDATE phpbb_newideas SET idea_text = '".$_POST["idea_text"]."' WHERE idea_id = '".$_POST["idea_id"]."'";
if( !$result = $db->sql_query($sql) )
{
message_die(GENERAL_ERROR, "Couldn't update idea table", "", __LINE__, __FILE__, $sql);
}

$message = $lang['Idea_Edited'] . "<br /><br /><a href=\"".append_sid("admin_ideas.$phpEx?mode=view")."\">". sprintf($lang['Click_Here_Go_Back'] . "</a>");
message_die(GENERAL_MESSAGE, $message);
}


include('./page_footer_admin.'.$phpEx);

?>

Link to comment
Share on other sites

BlueSkyIS ,

 

Thanks I will look at what you said. I also think I may need to reword what and when this occurs.

When you actually click the module it does not give error at that point. So if there is no messages or comments. then all looks fine. But if I post a message to another administrator it does post and show fine. But then above o top of page is when error occurs that occurs when you click the save message buttton. Then for every additional message that is added then a additional error message will be at top. So example if there is 3 messages then there will be that errror stated 3 times on top of page.

 

But then yes of course if I delete 1 or any of the messages then error goes away for every message deleted.

 

Thanks I will look at what you said. But your second response sorry not sure what you were asking ? sorry

Link to comment
Share on other sites

BlueSkyIS ,

 

Ok hope I don't show to much stupidy. But I am also not sure how exactly to add that die statement you suggested. Yes I know how to get to PHP file and then edit. But in general have been thrown into admin position of our forum and just starting to learn php. I do know how to use the find feature from text editor and find particular lines of code. But only if I have been given exact code to search for. and then also given exact statement to replace or add. Again but understanding what the code does. I am not afraid to admit 80-90 % of code I see is totally greek to me. So again just trying to be honest and up front with any and all. I am not afraid to learn but at this time have basically been droped in a position that needs more support than I can offer. So Below if I followed what you said to add I have posted. please let me know.

 

The existing code from above current php script:

 

{
$res = mysql_query("SELECT * FROM phpbb_newideas WHERE idea_status='$orderby' ORDER BY idea_id DESC");
}
else
{
$res = mysql_query("SELECT * FROM phpbb_newideas ORDER BY idea_status ASC, idea_id DESC");
}

Then with what you said to add if I did correctly and in the right place ?

$res = mysql_query("SELECT * FROM phpbb_newideas WHERE idea_status='$orderby' ORDER BY idea_id DESC");
}or die(mysql_error());
else
{
$res = mysql_query("SELECT * FROM phpbb_newideas ORDER BY idea_status ASC, idea_id DESC");
}or die(mysql_error());

 

Thanks and please let me know.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

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.