Losing my mind.... simple switch case..

Discussion in 'PHP' started by GeorgeB., Jul 31, 2006.

  1. #1
    OK up until now I considered myself a decent coder.. Apparently I was wrong.

    Am I missing something here? Why is the following switch code giving me an error: Parse error: parse error, expecting `':'' or `';'' in /my/server/dir/myfile.php on line 23 (Note: line 23 is actually the line 23 in the code below)


    
    switch ($filetype) {
    
            ## -------------------------------------------------- ##
            case "image/gif":
            copy ($_FILES['gameicon']['tmp_name'], "gameicons/".$_FILES['gameicon']['name']);
            break;
            ## -------------------------------------------------- ##
    
            ## -------------------------------------------------- ##
            case "image/jpg":
            copy ($_FILES['gameicon']['tmp_name'], "gameicons/".$_FILES['gameicon']['name']);
            break;
            ## -------------------------------------------------- ##
            
            ## -------------------------------------------------- ##
            case "image/png":
            copy ($_FILES['gameicon']['tmp_name'], "gameicons/".$_FILES['gameicon']['name']);
            break;
            ## -------------------------------------------------- ##
    
            default
            $formErrors['gameicon2'] = 'You did not upload a valid image.';
            }
    PHP:
    What's wrong with this switch??
     
    GeorgeB., Jul 31, 2006 IP
  2. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Missing colon after default.
     
    T0PS3O, Jul 31, 2006 IP
  3. Lukaslo

    Lukaslo Peon

    Messages:
    751
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #3
    try using:
    default;
    $formErrors['gameicon2'] = 'You did not upload a valid image.';
    break;

    it might work
     
    Lukaslo, Jul 31, 2006 IP
  4. GeorgeB.

    GeorgeB. Notable Member

    Messages:
    5,695
    Likes Received:
    288
    Best Answers:
    0
    Trophy Points:
    280
    #4
    OK well stab me with a rusty screw driver... that was it.

    How did I miss that colon. I must have stared at that word default for 5 minutes at least!
     
    GeorgeB., Jul 31, 2006 IP
  5. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Part of the game, who doesn't get that? Bloody annoying isn't it? :)

    If you use something like Zend Studio, chances are it would have highlighted the error there and then. One 'debugging' technique I use is to echo random shit from the error line up, every line. echo 'line 22'; etc. So you get to see exactly where it last executed a line. That's where the trouble will be.
     
    T0PS3O, Jul 31, 2006 IP
  6. coderlinks

    coderlinks Peon

    Messages:
    282
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Yeaa... I have invented my own version of debugging called... 'BLAH Debugging' :D . I put this code right from in a place
    
    echo 'blah';exit;
    
    PHP:
    If it says 'blah', I move it further down. Sometimes I use blah1 and blah2 at the same time :D. Really helps to remove some stupid errors.

    Thomas
     
    coderlinks, Aug 1, 2006 IP