| |||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | #1 (permalink) |
| The original NP Emo Kid | 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: |
| |
| | #2 (permalink) |
| Senior Member | What are you actually trying to do, Also try: PHP Code: |
| |
| | #5 (permalink) |
| The original NP Emo Kid | 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. |
| |
| | #6 (permalink) |
| NamePros Member | 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... |
| |
| | #7 (permalink) | |
| The original NP Emo Kid | Quote:
PHP Code: | |
| |
| | #8 (permalink) |
| NamePros Member | 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... |
| |
| | #11 (permalink) |
| NamePros Member | 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 |
| |
| | #13 (permalink) |
| NamePros Member | 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']) .\""));
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>';
|
| |
| | #15 (permalink) |
| NamePros Member | 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']) .\"");
Code: $temp = mysql_query("SELECT `locked` FROM `forum_topics` WHERE `id` = " . quote_smart($_GET['t']) );
![]() 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>'; |
| |
| | #16 (permalink) |
| The original NP Emo Kid | 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 ) ![]() This is the whole page if it helps at all PHP Code: |
| |
| | #18 (permalink) |
| Account Closed | 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. |
| |
| | #19 (permalink) |
| The original NP Emo Kid | 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. |
| |
| | #20 (permalink) | |
| The original NP Emo Kid | Quote:
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 ) | |
| |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| |