ecopetition Posted July 26, 2008 Share Posted July 26, 2008 Hey, I'm having a few problems with a forum script. It's doing exactly what it should be doing but is returning a few errors. Script: { $sql = "SELECT primary_group FROM users WHERE user_id = ". $forums[$i]['last_post_user_id'] ." "; $result = $db->query($sql); while($row = $db->fetch_assoc($result)) { $last_post_group_id[] = $row; } } { $sql = "SELECT group_colour FROM groups WHERE group_id = ". $last_post_group_id[0]['primary_group'] ." "; $result = $db->query($sql); while($row = $db->fetch_assoc($result)) { $newest_poster_colour[] = $row; } } It would appear to me that following errors are unjustified as the variables mentioned are defined above and the SQL queries would seem to be fine. Note that the variable '$i' varies the offset depending on what forum is being used. Errors: [Notice] Undefined variable: last_post_group_id (Line 199, File functions_forum.php) SELECT group_colour FROM groups WHERE group_id = Database Error Array ( [MSG] => You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3 [NUM] => 1064 ) [Notice] Undefined variable: newest_poster_colour (Line 227, File functions_forum.php) [Notice] Undefined offset: 5 (Line 199, File functions_forum.php) SELECT group_colour FROM groups WHERE group_id = Database Error Array ( [MSG] => You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3 [NUM] => 1064 ) [Notice] Undefined offset: 5 (Line 227, File functions_forum.php) [Notice] Undefined offset: 7 (Line 199, File functions_forum.php) SELECT group_colour FROM groups WHERE group_id = Database Error Array ( [MSG] => You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3 [NUM] => 1064 ) [Notice] Undefined offset: 7 (Line 227, File functions_forum.php) [Notice] Undefined offset: 8 (Line 199, File functions_forum.php) SELECT group_colour FROM groups WHERE group_id = Database Error Array ( [MSG] => You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3 [NUM] => 1064 ) [Notice] Undefined offset: 8 (Line 227, File functions_forum.php) [Notice] Undefined offset: 9 (Line 199, File functions_forum.php) SELECT group_colour FROM groups WHERE group_id = Database Error Array ( [MSG] => You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3 [NUM] => 1064 ) [Notice] Undefined offset: 9 (Line 227, File functions_forum.php) [Notice] Undefined offset: 10 (Line 199, File functions_forum.php) SELECT group_colour FROM groups WHERE group_id = Database Error Array ( [MSG] => You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3 [NUM] => 1064 ) Notice] Undefined offset: 10 (Line 227, File functions_forum.php) Notice] Undefined offset: 11 (Line 199, File functions_forum.php) SELECT group_colour FROM groups WHERE group_id = Database Error Array ( [MSG] => You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3 [NUM] => 1064 ) Notice] Undefined offset: 11 (Line 227, File functions_forum.php) If you can, please help me get rid of the errors. Thank you, Peter Quote Link to comment https://forums.phpfreaks.com/topic/116723-solved-unjustified-errors/ Share on other sites More sharing options...
wildteen88 Posted July 26, 2008 Share Posted July 26, 2008 The code your posted makes no sense, you'll need to post more code Quote Link to comment https://forums.phpfreaks.com/topic/116723-solved-unjustified-errors/#findComment-600178 Share on other sites More sharing options...
ecopetition Posted July 26, 2008 Author Share Posted July 26, 2008 It makes sense to me, it's two SQL queries, the second of which relies on the result of the first. Quote Link to comment https://forums.phpfreaks.com/topic/116723-solved-unjustified-errors/#findComment-600183 Share on other sites More sharing options...
.josh Posted July 26, 2008 Share Posted July 26, 2008 If it's doing what it's supposed to be doing but giving you those errors, maybe there is a problem with your error reporting system? Quote Link to comment https://forums.phpfreaks.com/topic/116723-solved-unjustified-errors/#findComment-600184 Share on other sites More sharing options...
ecopetition Posted July 26, 2008 Author Share Posted July 26, 2008 I can assure you there's not. Quote Link to comment https://forums.phpfreaks.com/topic/116723-solved-unjustified-errors/#findComment-600187 Share on other sites More sharing options...
.josh Posted July 26, 2008 Share Posted July 26, 2008 so...even though your query works fine and you're getting your desired results, you somehow think the problem is with your query string? If those sql errors were real, I assure you, you wouldn't be getting your desired results and things would not be working fine. Therefore, either your problem is your error reporting system, or else possibly you have some erroneous call(s) to that function, include(s), etc.. or w/e, where vars aren't being set, etc... in addition to your normal calls where the vars are set, etc... that could cause you to have errors and yet at the same time, have results. Because I promise you, if there's an error in your syntax, you don't get a result source returned. You get a false. Quote Link to comment https://forums.phpfreaks.com/topic/116723-solved-unjustified-errors/#findComment-600214 Share on other sites More sharing options...
ecopetition Posted July 26, 2008 Author Share Posted July 26, 2008 I think I know what the problem is, "$forums[$i]['last_post_user_id']" is sometimes blank, so it's like saying, "WHERE user_id = ", which I suspect is returning the database errors. I just don't know how to fix it. Quote Link to comment https://forums.phpfreaks.com/topic/116723-solved-unjustified-errors/#findComment-600249 Share on other sites More sharing options...
.josh Posted July 26, 2008 Share Posted July 26, 2008 well you can check if it exists before running it and either assign a default id number or not run it at all... Quote Link to comment https://forums.phpfreaks.com/topic/116723-solved-unjustified-errors/#findComment-600252 Share on other sites More sharing options...
ecopetition Posted July 26, 2008 Author Share Posted July 26, 2008 How would I assign a default? Quote Link to comment https://forums.phpfreaks.com/topic/116723-solved-unjustified-errors/#findComment-600258 Share on other sites More sharing options...
.josh Posted July 26, 2008 Share Posted July 26, 2008 well for instance if you wanted the default id to be 1: if (!$forums[$i]['last_post_user_id']) { $forums[$i]['last_post_user_id'] = 1; } Quote Link to comment https://forums.phpfreaks.com/topic/116723-solved-unjustified-errors/#findComment-600265 Share on other sites More sharing options...
ecopetition Posted July 26, 2008 Author Share Posted July 26, 2008 Problem solved Thank you for your enlightenment. Quote Link to comment https://forums.phpfreaks.com/topic/116723-solved-unjustified-errors/#findComment-600289 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.