PHP parse error help

Discussion in 'OT Technology' started by Dmar, Dec 31, 2005.

  1. Dmar

    Dmar Jump

    Joined:
    May 9, 2004
    Messages:
    344
    Likes Received:
    0
    Can someone please tell me why i get this error:
    Parse error: parse error, unexpected $ in /var/www/localhost/htdocs/basics/lens-calculator-2.php on line 46
    (line 45 is the last line)

    Code:
    <?php
    
    $distance_feet = $_POST['distance_in_feet'];
    $subject_feet = $_POST['subject_size_in_feet'];
    
    if ($distance_feet <= 0 || $subject_feet <= 0) 
    {
    echo "Input error";
    }
    else
    {
    
    $distance_inches = $distance_feet * 12;
    $subject_inches = $subject_feet * 12;
    $magnification = 1.5 / $subject_inches;
    $lens_focal_length_inches = $distance_inches / ((1/$magnification) + 1);
    $lens_focal_length_mm = round($lens_focal_length_inches * 25.4);
    
    echo <<<END
    <h2>$lens_focal_length_mm millimeters</h2> will do the job on a Nikon or Canon or similar 35mm camera.
    <p>
    Here are the raw numbers:
    <ul>
    <li>distance to your subject: $distance_feet feet ($distance_inches inches)
    <li>long dimension of your subject: $subject_feet feet ($subject_inches inches)
    <li>magnfication: $magnification
    <li>lens size required: $lens_focal_length_inches inches ($lens_focal_length_mm mm)
    </ul>
    </p>
    END;
    }
    
    ?>
    
     
  2. Penguin Man

    Penguin Man Protect Your Digital Liberties

    Joined:
    Apr 27, 2002
    Messages:
    21,696
    Likes Received:
    0
    Location:
    Edmonton, AB
    Works fine for me (assuming I give it valid input) :dunno:
     
  3. alex

    alex My neighbor got the gas chamber awhile back for do Moderator

    Joined:
    Oct 11, 2005
    Messages:
    24,383
    Likes Received:
    8
    Location:
    Orange County, NY
    .

    Yeah, just tested it on my server. Cannot replicate the error.
     
  4. CyberBullets

    CyberBullets I reach to the sky, and call out your name. If I c

    Joined:
    Nov 13, 2001
    Messages:
    11,865
    Likes Received:
    0
    Location:
    BC, Canada/Stockholm, Sweden
    im getting an error for your echo statement.

    php 5.0.4.
     
  5. CyberBullets

    CyberBullets I reach to the sky, and call out your name. If I c

    Joined:
    Nov 13, 2001
    Messages:
    11,865
    Likes Received:
    0
    Location:
    BC, Canada/Stockholm, Sweden
    did a few alterations...
    PHP:
    <?php
        
    //$distance_feet = $_POST['distance_in_feet'];
        //$subject_feet = $_POST['subject_size_in_feet'];
        
        
    $distance_feet 10;
        
    $subject_feet 10;

        if (
    $distance_feet <= || $subject_feet <= 0){
            echo 
    "Input error";
        }else{
            
    $distance_inches $distance_feet 12;
            
    $subject_inches $subject_feet 12;
            
    $magnification 1.5 $subject_inches;
            
    $lens_focal_length_inches $distance_inches / ((1/$magnification) + 1);
            
    $lens_focal_length_mm round($lens_focal_length_inches 25.4);
        
            echo 
    "<h2>$lens_focal_length_mm millimeters</h2> will do the job on a Nikon or Canon or similar 35mm camera." .
                
    "<p>" .
                
    "Here are the raw numbers:" .
                
    "<ul>" .
                
    "<li>distance to your subject: $distance_feet feet ($distance_inches inches)</li>" .
                
    "<li>long dimension of your subject: $subject_feet feet ($subject_inches inches)</li>" .
                
    "<li>magnfication: $magnification</li>" .
                
    "<li>lens size required: $lens_focal_length_inches inches ($lens_focal_length_mm mm)</li>" .
                
    "</ul>" .
                
    "</p>";
        }
    ?>
     

Share This Page