[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

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


Closed Thread
 
LinkBack Thread Tools
Old 05-15-2006, 10:57 AM   #1 (permalink)
The original NP Emo Kid
 
liam_d's Avatar
 
Join Date: Jan 2005
Location: Plymouth, UK
Posts: 1,648
0.00 NP$ (Donate)

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
$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, 11:15 AM   #2 (permalink)
Senior Member
 
Xyzer's Avatar
 
Join Date: Aug 2005
Location: United Kindom
Posts: 1,506
90.70 NP$ (Donate)

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 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'];

if (
$locked['locked'] == '1')
{
    
message($lang['title']['topic_locked'].$lang['text']['locked']);
}
Xyzer is offline  
Old 05-15-2006, 11:30 AM   #3 (permalink)
The original NP Emo Kid
 
liam_d's Avatar
 
Join Date: Jan 2005
Location: Plymouth, UK
Posts: 1,648
0.00 NP$ (Donate)

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, 11:33 AM   #4 (permalink)
Senior Member
 
Xyzer's Avatar
 
Join Date: Aug 2005
Location: United Kindom
Posts: 1,506
90.70 NP$ (Donate)

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 all

Tsunami Relief AIDS/HIV
fine, at least i tried did you try it then?
Xyzer is offline  
Old 05-15-2006, 11:40 AM   #5 (permalink)
The original NP Emo Kid
 
liam_d's Avatar
 
Join Date: Jan 2005
Location: Plymouth, UK
Posts: 1,648
0.00 NP$ (Donate)

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, 04:12 PM   #6 (permalink)
NamePros Member
 
Join Date: May 2006
Posts: 160
81.00 NP$ (Donate)

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!

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, 12:29 AM   #7 (permalink)
The original NP Emo Kid
 
liam_d's Avatar
 
Join Date: Jan 2005
Location: Plymouth, UK
Posts: 1,648
0.00 NP$ (Donate)

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


Quote:
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'];
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, 04:57 AM   #8 (permalink)
NamePros Member
 
Join Date: May 2006
Posts: 160
81.00 NP$ (Donate)

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, 05:08 AM   #9 (permalink)
The original NP Emo Kid
 
liam_d's Avatar
 
Join Date: Jan 2005
Location: Plymouth, UK
Posts: 1,648
0.00 NP$ (Donate)

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

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 05:45 AM.
liam_d is offline  
Old 05-16-2006, 01:46 PM   #10 (permalink)
NamePros Member
 
Join Date: Nov 2003
Location: Ontario, Canada
Posts: 91
80.80 NP$ (Donate)

eagle12 is on a distinguished road


Can you post more of the code, because it looks like the code you posted is fine.
eagle12 is offline  
Old 05-16-2006, 02:05 PM   #11 (permalink)
NamePros Member
 
Join Date: May 2006
Posts: 160
81.00 NP$ (Donate)

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, 08:04 AM   #12 (permalink)
The original NP Emo Kid
 
liam_d's Avatar
 
Join Date: Jan 2005
Location: Plymouth, UK
Posts: 1,648
0.00 NP$ (Donate)

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, 08:11 AM   #13 (permalink)
NamePros Member
 
Join Date: May 2006
Posts: 160
81.00 NP$ (Donate)

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...
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, 08:34 AM   #14 (permalink)
The original NP Emo Kid
 
liam_d's Avatar
 
Join Date: Jan 2005
Location: Plymouth, UK
Posts: 1,648
0.00 NP$ (Donate)

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, 08:45 AM   #15 (permalink)
NamePros Member
 
Join Date: May 2006
Posts: 160
81.00 NP$ (Donate)

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, 09:11 AM   #16 (permalink)
The original NP Emo Kid
 
liam_d's Avatar
 
Join Date: Jan 2005
Location: Plymouth, UK
Posts: 1,648
0.00 NP$ (Donate)

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']) . "'"));

    

    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']);

    }

    

    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, 01:47 PM   #17 (permalink)
NamePros Member
 
Join Date: May 2006
Posts: 160
81.00 NP$ (Donate)

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, 02:46 PM   #18 (permalink)
Account Closed
 
abdulmueid's Avatar
 
Join Date: Jun 2005
Location: Mozambique
Posts: 608
1.85 NP$ (Donate)

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, 02:21 AM   #19 (permalink)
The original NP Emo Kid
 
liam_d's Avatar
 
Join Date: Jan 2005
Location: Plymouth, UK
Posts: 1,648
0.00 NP$ (Donate)

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, 02:38 AM   #20 (permalink)
The original NP Emo Kid
 
liam_d's Avatar
 
Join Date: Jan 2005
Location: Plymouth, UK
Posts: 1,648
0.00 NP$ (Donate)

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


Quote:
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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 01:01 PM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85