Page 1 of 2 12 LastLast
Results 1 to 10 of 42

Thread: Day 4 - Decision Making - Become PHP Expert in 30 days

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2009
    Posts
    76,596

    Default

    I got an error

    http://php.flashwebhost.com/sherly/medicine.php

    Code:
    Parse error:  syntax error, unexpected 'if' (T_IF) in /home/fwhphp/public_html/sherly/medicine.php on line 3
    Code:
    <?php
    $overtime=40
    if ($overtime<=60)
    {
    $pay_amount=1500;
    $medicine=1000;
    echo 'Pay Amount : $pay_amount : Medicine : $medicine';
    }
    else
    {
    $$pay_amount=2000;
    $medicine=1700;
    echo 'pay Amount : $pay_amount : Medicine : $medicine';
    }

  2. #2
    Join Date
    Sep 2003
    Posts
    3,040

    Default

    $overtime=40
    Missing ending semicolon (;)
    Become PHP Expert in 30 days
    FreeMarriage.com - Free Online Matrimonial
    FlashWebHost.com - Professional Web Hosting, Designing.

  3. #3
    Join Date
    Sep 2003
    Location
    india
    Posts
    11,527

    Default

    http://php.flashwebhost.com/annie/if...reater_bug.php

    Code:
    <?php
    $passScore = 210;
    $studentName = 'Mike';
    $studentScore = 190;
    if ($studentScore > $passScore) {
    echo 'Congratulations' . $studentName . 'You passed the exam with' . $studentMark . 'mark.';
    } else {
    
    echo 'Passing Score is'  .  $passScore . '.Your Score is' . $studentScore ; 
    
    echo '<br>';
    
    echo 'Sorry You did not pass the exam. Good luck and Cheers next time. ';
    }

  4. #4
    Join Date
    Sep 2003
    Posts
    3,040

    Default

    Quote Originally Posted by annie View Post
    http://php.flashwebhost.com/annie/if...reater_bug.php

    Code:
    <?php
    $passScore = 210;
    $studentName = 'Mike';
    $studentScore = 190;
    if ($studentScore > $passScore) {
    echo 'Congratulations' . $studentName . 'You passed the exam with' . $studentMark . 'mark.';
    } else {
    
    echo 'Passing Score is'  .  $passScore . '.Your Score is' . $studentScore ; 
    
    echo '<br>';
    
    echo 'Sorry You did not pass the exam. Good luck and Cheers next time. ';
    }
    echo 'Congratulations' . $studentName . 'You passed the exam with' . $studentMark . 'mark.';
    On this line, you have $studentMark, this variable is not defined (created/used) in that program.. It should be replaced with $studentScore.

    Use tab for indent code inside { and }, refer my code. Code inside { and } is called code block, must be indented (press TAB key).
    Become PHP Expert in 30 days
    FreeMarriage.com - Free Online Matrimonial
    FlashWebHost.com - Professional Web Hosting, Designing.

  5. #5
    Join Date
    Sep 2003
    Location
    india
    Posts
    11,527

    Default

    Try this code

    Code:
    <?php
    $overtime=40;
    if ($overtime<=60)
    {
    $pay_amount=1500;
    $medicine=1000;
    echo 'Pay Amount ' . $pay_amount .' Medicine ' . $medicine;
    }
    else
    {
    $pay_amount=2000;
    $medicine=1700;
    echo 'pay Amount ' . $pay_amount . ' Medicine ' . $medicine;
    }

    Quote Originally Posted by sherlyk View Post
    I got an error

    http://php.flashwebhost.com/sherly/medicine.php

    Code:
    Parse error:  syntax error, unexpected 'if' (T_IF) in /home/fwhphp/public_html/sherly/medicine.php on line 3
    Code:
    <?php
    $overtime=40
    if ($overtime<=60)
    {
    $pay_amount=1500;
    $medicine=1000;
    echo 'Pay Amount : $pay_amount : Medicine : $medicine';
    }
    else
    {
    $$pay_amount=2000;
    $medicine=1700;
    echo 'pay Amount : $pay_amount : Medicine : $medicine';
    }

  6. #6
    Join Date
    Feb 2005
    Location
    India
    Posts
    11,004

    Default

    http://php.flashwebhost.com/melbin/days.php

    PHP Code:
    <?php
    $day
    ='Sunday';
    if (
    $day="Sunday") {
        echo 
    'Have a nice Sunday';
    }

    else {
        echo 
    'Have a nice day';
    }
    In this code when i use == on line no:3
    if ($day=="Sunday") {
    i am getting the result as FALSE. Why ?

    Doubt 2

    Is it possible to get the day by using PHP date and time function ?
    VIDEO WORLD : LATEST HOLLYWOOD || BOLLYWOOD || SOUTH INDIAN VIDEOS || TRAILERS

  7. #7
    Join Date
    Feb 2005
    Location
    India
    Posts
    11,004

    Default

    http://php.flashwebhost.com/melbin/result.php

    PHP Code:
    <?php
    $mark
    =85; // Enter Mark between 1 and 100

    if ($mark > 100){
        echo 
    "$mark/100 ???... INVALID MARK";
    }

    else if (
    $mark >= 80 and $mark <= 100){
        echo 
    'Congratulations You have got ' . $mark . ' Marks - Grade : Distinction';
    }

    else if (
    $mark >=60 and $mark <80) {
        echo 
    'Congratulations You have got ' . $mark . ' Marks - Grade : First Class';
    }

    else if (
    $mark >=50 and $mark <60) {
        echo 
    'Congratulations You have got ' . $mark . ' Marks - Grade : Second Class';
    }

    else if (
    $mark >=0 and $mark <50) {
        echo 
    'Sorry You did not pass the exam. Your Mark is ' . $mark . ' - Status : FAILED';
    }

    else {
        echo 
    'INVALID MARK';
    }
    Last edited by melbin; 05-13-2014 at 03:39 AM. Reason: script url missed
    VIDEO WORLD : LATEST HOLLYWOOD || BOLLYWOOD || SOUTH INDIAN VIDEOS || TRAILERS

  8. #8
    Join Date
    Sep 2003
    Posts
    3,040

    Default

    Quote Originally Posted by melbin View Post
    http://php.flashwebhost.com/melbin/result.php

    PHP Code:
    <?php
    $mark
    =85; // Enter Mark between 1 and 100

    if ($mark > 100){
        echo 
    "$mark/100 ???... INVALID MARK";
    }

    else if (
    $mark >= 80 and $mark <= 100){
        echo 
    'Congratulations You have got ' . $mark . ' Marks - Grade : Distinction';
    }

    else if (
    $mark >=60 and $mark <80) {
        echo 
    'Congratulations You have got ' . $mark . ' Marks - Grade : First Class';
    }

    else if (
    $mark >=50 and $mark <60) {
        echo 
    'Congratulations You have got ' . $mark . ' Marks - Grade : Second Class';
    }

    else if (
    $mark >=0 and $mark <50) {
        echo 
    'Sorry You did not pass the exam. Your Mark is ' . $mark . ' - Status : FAILED';
    }

    else {
        echo 
    'INVALID MARK';
    }
    Good script.
    Become PHP Expert in 30 days
    FreeMarriage.com - Free Online Matrimonial
    FlashWebHost.com - Professional Web Hosting, Designing.

  9. #9
    Join Date
    Nov 2009
    Posts
    76,596

    Default

    http://php.flashwebhost.com/sherly/discount.php

    Code:
    <?php 
     $over65=true; 
     $price = 3.00; 
     if ($over65) 
     { 
     $discount =.90; 
    echo  "You have received our senior's discount, your price is $" . $price*$discount; 
     } 
     else 
     { 
    echo "Sorry you do not qualify for a discount, your price is $" . $price; 
     } 
     ?>
    Last edited by sherlyk; 05-13-2014 at 07:30 AM.

  10. #10
    Join Date
    Nov 2004
    Location
    India
    Posts
    65

    Default

    http://php.flashwebhost.com/stefin/fish_can_fly.php

    Code:
    <?php
    $fishsCanFly = 'yes';
    if ($fishsCanFly == 'yes') {
    echo 'then we can never have a fish curry' ;
     }
    if ( $fishsCanFly == 'no') {
    echo 'then we can have as much fish as we want' ;
     }

Page 1 of 2 12 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •