NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Strange php error - been bugging me!!

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 05-15-2006, 11:57 AM THREAD STARTER               #1 (permalink)
The original NP Emo Kid
 
liam_d's Avatar
Join Date: Jan 2005
Location: Plymouth, UK
Posts: 1,693
liam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to all
 




Strange php error - been bugging me!!


Ok this bug is really getting on my coding tits!!

Basically this is checking if a forum topic is locked or not.

I have this:
PHP Code:
// checked the topic is not locked
????: NamePros.com http://www.namepros.com/programming/197582-strange-php-error-been-bugging-me.html
$locked mysql_fetch_array(mysql_query("SELECT `locked` FROM `forum_topics` WHERE `id` = '" quote_smart($_GET['t']) . "'"));

echo 
"blah" $locked['locked'];

if (
$locked['locked'] == '1')
{
    
message($lang['title']['topic_locked'],$lang['text']['locked']);

And if anyone signs up at www.milztech.com/forum/ create a topic in the test area and then go to edit it. You will see blah0 meaning the locked string is actually at 0 yet it still says its locked?!!
liam_d is offline  
Old 05-15-2006, 12:15 PM   #2 (permalink)
Senior Member
 
Xyzer's Avatar
Join Date: Aug 2005
Location: United Kindom
Posts: 1,502
Xyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to all
 


Tsunami Relief AIDS/HIV
What are you actually trying to do,

Also try:
PHP Code:
 // checked the topic is not locked 
$locked mysql_fetch_array(mysql_query("SELECT `locked` FROM `forum_topics` WHERE `id` = \" . quote_smart($_GET['t']) .\"")); 

echo 
"blah" $locked['locked']; 
????: NamePros.com http://www.namepros.com/showthread.php?t=197582

if (
$locked['locked'] == '1'

    
message($lang['title']['topic_locked'].$lang['text']['locked']); 

Xyzer is offline  
Old 05-15-2006, 12:30 PM THREAD STARTER               #3 (permalink)
The original NP Emo Kid
 
liam_d's Avatar
Join Date: Jan 2005
Location: Plymouth, UK
Posts: 1,693
liam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to all
 




All i am trying to do is check a variable, yet it always says it's set to 1 when it's not.

What you put won't help no offense.
liam_d is offline  
Old 05-15-2006, 12:33 PM   #4 (permalink)
Senior Member
 
Xyzer's Avatar
Join Date: Aug 2005
Location: United Kindom
Posts: 1,502
Xyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to all
 


Tsunami Relief AIDS/HIV
fine, at least i tried did you try it then?
Xyzer is offline  
Old 05-15-2006, 12:40 PM THREAD STARTER               #5 (permalink)
The original NP Emo Kid
 
liam_d's Avatar
Join Date: Jan 2005
Location: Plymouth, UK
Posts: 1,693
liam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to all
 




Well for one there should be a , not a . in the message function as a . links them together while , seperates them as there are two parts to the function.

And second quoting what i already have and putting in slashes just does exactly the same thing as what i have in the mysql_query.
liam_d is offline  
Old 05-15-2006, 05:12 PM   #6 (permalink)
NamePros Member
Join Date: May 2006
Posts: 160
TwistMyArm is on a distinguished road
 



In reality, you shouldn't be using any form of quotes in the SQL around your ID value (not single quotes or double quotes): unless your ID actually isn't a number!
????: NamePros.com http://www.namepros.com/showthread.php?t=197582

I'm guessing that it's more a problem with the query or the population of the array.

What happens if you add the lines:
print '<pre>';
print_r($locked);
print '</pre>';

after the line where you assign the SQL output to the $locked variable?

Just a guess, but not knowing anything else about your code it's as good as any... I would guess that the locked variable shows to be an empty array, which would mean there's something wrong with one of the MySQL function calls.

If that is the case, call mysql_error() or whatever the function is and see what it says...
TwistMyArm is offline  
Old 05-16-2006, 01:29 AM THREAD STARTER               #7 (permalink)
The original NP Emo Kid
 
liam_d's Avatar
Join Date: Jan 2005
Location: Plymouth, UK
Posts: 1,693
liam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to all
 




Originally Posted by TwistMyArm
In reality, you shouldn't be using any form of quotes in the SQL around your ID value (not single quotes or double quotes): unless your ID actually isn't a number!

I'm guessing that it's more a problem with the query or the population of the array.

What happens if you add the lines:
print '<pre>';
print_r($locked);
print '</pre>';

after the line where you assign the SQL output to the $locked variable?

Just a guess, but not knowing anything else about your code it's as good as any... I would guess that the locked variable shows to be an empty array, which would mean there's something wrong with one of the MySQL function calls.

If that is the case, call mysql_error() or whatever the function is and see what it says...
Thanks but read my code and you see this bit:
PHP Code:
echo "blah" $locked['locked']; 
????: NamePros.com http://www.namepros.com/showthread.php?t=197582
It comes out as blah0 (i added blah to see where it is incase nothing came out) so it is deffinatly set!
liam_d is offline  
Old 05-16-2006, 05:57 AM   #8 (permalink)
NamePros Member
Join Date: May 2006
Posts: 160
TwistMyArm is on a distinguished road
 



By 'set' I mean defined: either $locked['locked'] is set to 0, or it's not set at all and so the printout defaults to zero.

I'm guessing the latter, but hey, if you're so sure about what you're doing that you're not even able to try three lines of code, go ahead...
TwistMyArm is offline  
Old 05-16-2006, 06:08 AM THREAD STARTER               #9 (permalink)
The original NP Emo Kid
 
liam_d's Avatar
Join Date: Jan 2005
Location: Plymouth, UK
Posts: 1,693
liam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to all
 




I didn't mean it like that buddy, i will try what you put, thanks for your help
????: NamePros.com http://www.namepros.com/showthread.php?t=197582

I get this:
PHP Code:
Array
(
    [
0] => 0
    
[locked] => 0

So it is correct at 0! Yet it doesn't work!
Last edited by liam_d; 05-16-2006 at 06:45 AM.
liam_d is offline  
Old 05-16-2006, 02:46 PM   #10 (permalink)
NamePros Member
Join Date: Nov 2003
Location: Ontario, Canada
Posts: 127
eagle12 will become famous soon enougheagle12 will become famous soon enough
 



Can you post more of the code, because it looks like the code you posted is fine.
eagle12 is offline  
Old 05-16-2006, 03:05 PM   #11 (permalink)
NamePros Member
Join Date: May 2006
Posts: 160
TwistMyArm is on a distinguished road
 



Hmmm...

MySQL can be picky, but only sometimes What happens if you change your query from:
"SELECT `locked` FROM `forum_topics` WHERE `id` = '" . quote_smart($_GET['t']) . "'"

to:
"SELECT `locked` FROM `forum_topics` WHERE `id` = " . quote_smart($_GET['t']);

(notice the removal of quotes around the ID).

I'd also add:
print mysql_error();

after the query to make sure that it worked, plus... run a print_r on $_GET: just make sure that it was populated correctly, too.

Other than that, yeah, we need more code
TwistMyArm is offline  
Old 05-21-2006, 09:04 AM THREAD STARTER               #12 (permalink)
The original NP Emo Kid
 
liam_d's Avatar
Join Date: Jan 2005
Location: Plymouth, UK
Posts: 1,693
liam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to all
 




I tried all of that, no difference, all the $_GET bits are there. There is no mysql error.

This is really getting to me now
liam_d is offline  
Old 05-21-2006, 09:11 AM   #13 (permalink)
NamePros Member
Join Date: May 2006
Posts: 160
TwistMyArm is on a distinguished road
 



Hmmm... I guess the only other thing I can suggest is that *if* there's a problem with the query, the mysql_error function won't show anything as it only shows the result of the last MySQL function (which is your mysql_fetch_array call).

Have you tried spliting:
Code:
$locked = mysql_fetch_array(mysql_query("SELECT `locked` FROM `forum_topics` WHERE `id` = \" . quote_smart($_GET['t']) .\""));
into two separate calls and check for an error between the two, like...
????: NamePros.com http://www.namepros.com/showthread.php?t=197582
Code:
$temp = mysql_query("SELECT `locked` FROM `forum_topics` WHERE `id` = \" . quote_smart($_GET['t']) .\"");
print 'First function: ' . mysql_error() . '<br>';
$locked = mysql_fetch_array($temp);
print 'Second function: ' . mysql_error() . '<br>';
TwistMyArm is offline  
Old 05-21-2006, 09:34 AM THREAD STARTER               #14 (permalink)
The original NP Emo Kid
 
liam_d's Avatar
Join Date: Jan 2005
Location: Plymouth, UK
Posts: 1,693
liam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to all
 




There are no errors being printed out
liam_d is offline  
Old 05-21-2006, 09:45 AM   #15 (permalink)
NamePros Member
Join Date: May 2006
Posts: 160
TwistMyArm is on a distinguished road
 



Oops. Sorry. Just noticed that I copied your original query which probably wouldn't work anyway!

Change:
Code:
$temp = mysql_query("SELECT `locked` FROM `forum_topics` WHERE `id` = \" . quote_smart($_GET['t']) .\"");
to:
Code:
$temp = mysql_query("SELECT `locked` FROM `forum_topics` WHERE `id` = " . quote_smart($_GET['t']) );
while still keeping the error checks in there and then see what happens... Fingers crossed

I'd probably also add something like:
Code:
$query = "SELECT `locked` FROM `forum_topics` WHERE `id` = " . quote_smart($_GET['t']);
print 'Query is: ' . $query . '<br>';
Just in case the quote_smart function is doing something funky...
TwistMyArm is offline  
Old 05-21-2006, 10:11 AM THREAD STARTER               #16 (permalink)
The original NP Emo Kid
 
liam_d's Avatar
Join Date: Jan 2005
Location: Plymouth, UK
Posts: 1,693
liam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to all
 




I now get
Code:
First function:
Second function:
Query is: SELECT `locked` FROM `forum_topics` WHERE `id` = 60
blah0
Array ( [act] => editpost [t] => 60 [f] => 10 [ist] => 1 )
And it still gives me the topic locked box

This is the whole page if it helps at all
PHP Code:
<?php
/*
CherryBB Copyright 2006 Liam Dawe
*/

// Check the group
check_group();

// permissions
$permissions mysql_fetch_array(mysql_query("SELECT `cpost`,`cview` FROM `permissions` WHERE `group` = '" quote_smart($_SESSION['group']) . "' AND `forum` = '" quote_smart($_GET['f']) . "'"));

if (
$permissions['cpost'] == '0' || $permissions['cview'] == '0')
{
    
message($lang['title']['no_post'],$lang['text']['no_post']);
}

 
// checked the topic is not locked
$temp mysql_query("SELECT `locked` FROM `forum_topics` WHERE `id` = " quote_smart($_GET['t']) );
print 
'First function: ' mysql_error() . '<br>';
$locked mysql_fetch_array($temp);
print 
'Second function: ' mysql_error() . '<br>';
$query "SELECT `locked` FROM `forum_topics` WHERE `id` = " quote_smart($_GET['t']);
print 
'Query is: ' $query '<br>';

echo 
"blah" $locked['locked'] . "<br />";
print_r ($_GET);

if (
$locked['locked'] == '1')
{
    
message($lang['title']['topic_locked'],$lang['text']['locked']);
}  

else if (!isset(
$_GET['action']))
{    
    
// Get the forum and category name from the url
    
$forum_name mysql_fetch_array(mysql_query("SELECT `name`,`category` FROM `forums` WHERE `id` = '" quote_smart($_GET['f']) . "'")) or die(mysql_error());

    
$category_name mysql_fetch_array(mysql_query("SELECT `name` FROM `forums` WHERE `id` = '" quote_smart($forum_name['category']) . "'"));

    
display_clickable_smilies_bbcode();

    
// if is topic
    
if ($_GET['ist'] == '1')
    {
        
$edit_body mysql_fetch_array(mysql_query("SELECT `body` FROM `forum_topic_text` WHERE `topic_id` = '" quote_smart($_GET['t']) . "'"));
    }
    

    
// if is reply
    
else if ($_GET['ist'] == '0')
    {
        
$edit_body mysql_fetch_array(mysql_query("SELECT `body` FROM `forum_reply_text` WHERE `reply_id` = '" quote_smart($_GET['reply']) . "'"));
    }

    
// make post readable for editing
    
message($lang['title']['topic_locked'],$lang['text']['locked']);
    
    
$edit_body['body'] = edit_post_parser($edit_body['body']);

    
// get the file to use
    
get_template('editpost');    

}



// Edit Post

else if ($_GET['action'] == 'edit'

{

    
$locker_exists mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_topics` WHERE `id` = '" quote_smart($_GET['t']) . "'"));
????: NamePros.com http://www.namepros.com/showthread.php?t=197582

    

    if (
$locker_exists['locked'] == '1'

    {

        
message($lang['title']['topic_locked'],$lang['text']['locked']);

    }

    

    else if (!isset(
$_GET['t']))

    {

        
message($lang['title']['no_topic_id'],$lang['title']['no_topic_id']);
????: NamePros.com http://www.namepros.com/showthread.php?t=197582

    }

    

    else if (empty(
$locker_exists)) 

    {

        
message($lang['title']['no_topic_id'],$lang['title']['no_topic_id']);

    }

    

    else if (!isset(
$_POST['body1'])) 

    {

        
message($lang['title']['no_body'],$lang['text']['no_body']);

    }

    

    else

    {

        if (
$_GET['ist'] == '1')

        {
            
// post parsing
            
main_post_parser();

            
// Insert the reply body
            
mysql_query("UPDATE `forum_topic_text` set `body` = '" quote_smart($_POST['body1']) . "' WHERE `topic_id` = '" quote_smart($_GET['t']) . "'") or die(mysql_error());

            
message($lang['title']['post_edited'], $lang['text']['post_edited']);
        }

        

        else if (
$_GET['ist'] == '0')
        {
            
// post parsing
            
main_post_parser();

            
// Insert the reply body
            
mysql_query("UPDATE `forum_reply_text` set `body` = '" quote_smart($_POST['body1']) . "' WHERE `reply_id` = '" quote_smart($_GET['reply']) . "'") or die(mysql_error());

            
message($lang['title']['post_edited'],$lang['text']['post_edited']);

        }

    }

}

?>
liam_d is offline  
Old 05-21-2006, 02:47 PM   #17 (permalink)
NamePros Member
Join Date: May 2006
Posts: 160
TwistMyArm is on a distinguished road
 



OK... so to be honest, I'm running out of ideas...

What is the output if you add:
print_r ($locked);

after:
print_r ($_GET);

?
TwistMyArm is offline  
Old 05-21-2006, 03:46 PM   #18 (permalink)
Account Closed
 
abdulmueid's Avatar
Join Date: Jun 2005
Location: Mozambique
Posts: 607
abdulmueid has a spectacular aura aboutabdulmueid has a spectacular aura about
 



Hello Liam,

The first glimpse at the full code that you have posted above shows me that the problem is in the later part of the code. I will just point out the thing I have noticed.

$_GET['action'] does not exist. Instead it should be $_GET['act']. $_GET fetches a variable from the URL and if you look at the URL, the action variable is called "act" ex. index.php?act=viewtopic. The output from print_r($_GET); also gave you 'act' as the variable and not 'action'.

Try changing all the occurrences of $_GET['action'] to $_GET['act'].

I will take a good look at the code maybe tomorrow during my free time.
abdulmueid is offline  
Old 05-22-2006, 03:21 AM THREAD STARTER               #19 (permalink)
The original NP Emo Kid
 
liam_d's Avatar
Join Date: Jan 2005
Location: Plymouth, UK
Posts: 1,693
liam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to all
 




Thanks for your reply but act and action are actually different things.

Act is the module which is being loaded while action is something within the script that is going on.

I will add the other print_r when i get back to my desk later on today.

Thanks.
liam_d is offline  
Old 05-28-2006, 03:38 AM THREAD STARTER               #20 (permalink)
The original NP Emo Kid
 
liam_d's Avatar
Join Date: Jan 2005
Location: Plymouth, UK
Posts: 1,693
liam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to all
 




Originally Posted by TwistMyArm
OK... so to be honest, I'm running out of ideas...

What is the output if you add:
print_r ($locked);

after:
print_r ($_GET);

?
i now have this, sorry for such a late reply
Code:
First function:
Second function:
Query is: SELECT `locked` FROM `forum_topics` WHERE `id` = 3
blah0
Array ( [act] => editpost [t] => 3 [f] => 10 [ist] => 1 )
Array ( [0] => 0 [locked] => 0 )
liam_d is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 07:50 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger