Jump to content

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


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!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.