Jump to content

Parse error: syntax error, unexpected T_STRING in modify.php on line 48


tlclady

Recommended Posts

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;

}

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?

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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.