tlclady Posted September 14, 2010 Share Posted September 14, 2010 Can anyone please tell me what is wrong with this code?! I keep getting: Parse error: syntax error, unexpected T_STRING in modify.php on line 48 // build combo box options $list = ''; foreach ($categories as $key => $value) { $name = $value['name']; $children = $value['children']; $list .= " if ($key == $catId) { $list.= " selected"; { } $list .= ">$name\r\n"; foreach ($children as $child) { $list .= " if ($child['id'] == $catId) { $list.= " selected"; } $list .= "> {$child['name']}\r\n"; } } return $list; } Quote Link to comment https://forums.phpfreaks.com/topic/213405-parse-error-syntax-error-unexpected-t_string-in-modifyphp-on-line-48/ Share on other sites More sharing options...
Pikachu2000 Posted September 14, 2010 Share Posted September 14, 2010 There aren't 48 lines in that code. Please enclose the code in . . . tags and indicate which line is line 48. Quote Link to comment https://forums.phpfreaks.com/topic/213405-parse-error-syntax-error-unexpected-t_string-in-modifyphp-on-line-48/#findComment-1111058 Share on other sites More sharing options...
tlclady Posted September 14, 2010 Author Share Posted September 14, 2010 Complete code module is enclosed. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/213405-parse-error-syntax-error-unexpected-t_string-in-modifyphp-on-line-48/#findComment-1111059 Share on other sites More sharing options...
Pikachu2000 Posted September 14, 2010 Share Posted September 14, 2010 No offense intended, but quite honestly, that code is a mess. You're attempting to concatenate if(){} conditionals to strings, causing parse errors. I may be mistaken on this one but I'm unaware of any reason to use 'return' outside of a function definition. There's an extra closing curly brace. The first query is wide open to SQL injection. There's no exit() after the header() redirect, so the code will continue to execute even after the redirect. The constant 'PRODUCT_IMAGE_DIR' appears to never get defined and there are no slashes in that directory path. What is it you're trying to accomplish with this? There may be a much easier way to do it. EDIT: Also, is this part of another application, and you're trying to make some changes? If it is, which application is it? Quote Link to comment https://forums.phpfreaks.com/topic/213405-parse-error-syntax-error-unexpected-t_string-in-modifyphp-on-line-48/#findComment-1111067 Share on other sites More sharing options...
tlclady Posted September 14, 2010 Author Share Posted September 14, 2010 LOL...no offense taken....I didn't write the code. I'm new to PHP, but since I can't make heads or tails out of this code that I got from a website http://www.phpwebcommerce.com/ your comment actually makes me feel better. Anyway, the problem is the combo box. It is not allowing me to select the categories that I added. Supposedly, the code I shared with you is supposed to fix that, but..... See http://www.phpwebcommerce.com/qna/detail/add-products-to-category.php. Hopefully, that will give you information about what I'm trying to do. Thank you very much for responding. If you have any suggestions, that would be great, but I'm about to abandon the whole application and look elsewhere since I suspect it is, as you say, frankly a mess! Quote Link to comment https://forums.phpfreaks.com/topic/213405-parse-error-syntax-error-unexpected-t_string-in-modifyphp-on-line-48/#findComment-1111115 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.