Web Design Forum: What's wrong with this PHP code? - Web Design Forum

Jump to content

WDF
WDF Premium Memberships Reseller Hosting
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

What's wrong with this PHP code? Rate Topic: -----

#1 User is offline   garym 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 12
  • Joined: 12-January 12
  • Reputation: 0

Posted 23 January 2012 - 09:28 PM

Hi,

I'm currently learning php and am playing around with statements at the moment. I've typed some code but when it's accessed the page is blank. Would somebody mind taking a look at it for me please and let me know what i'm doing wrong? :)

Here's the code:

<html>
    <head>
            <title>Logical Expressions:Switch/title>
            </head>
            <body>
    <?php $a = 3; ?>
    
    
    <?php
    
    switch ($a) {
        case 0:
        echo "a equals 0";
            break;
            case 1:
            echo "a equals 1";
                break;
            case 2:
            echo "a equals 2";
                break;
            default:
            echo "a is not 0,1 or 2";
            break;
    }
    
    ?>
            
            </body>
            </html>


Thanks for looking.

Gary :)
0

#2 User is offline   Jay Gilford 

  • Web Guru
  • PipPipPipPipPip
  • Group: Members
  • Posts: 1,105
  • Joined: 11-October 09
  • Reputation: 185
  • Gender:Male
  • Experience:Web Guru
  • Area of Expertise:Web Developer

Posted 23 January 2012 - 09:30 PM

That should work perfectly. My guess is you don't have php parsing on when it's run. Do you have the .html extension instead of .php?
1

#3 User is offline   garym 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 12
  • Joined: 12-January 12
  • Reputation: 0

Posted 23 January 2012 - 09:35 PM

View PostJay Gilford, on 23 January 2012 - 09:30 PM, said:

That should work perfectly. My guess is you don't have php parsing on when it's run. Do you have the .html extension instead of .php?


Thanks for your help.

I am not sure how to check if I have parsing on?

I did save the file with a .html extension too but nothing appeared to show.
0

#4 User is offline   Jay Gilford 

  • Web Guru
  • PipPipPipPipPip
  • Group: Members
  • Posts: 1,105
  • Joined: 11-October 09
  • Reputation: 185
  • Gender:Male
  • Experience:Web Guru
  • Area of Expertise:Web Developer

Posted 23 January 2012 - 09:37 PM

Have you set a webserver up on your local machine? or are you using hosting to test this?
If you haven't set up a webserver, I'd recommend WAMP or XAMPP for windows. html is not parsed as PHP. to parse php, you need to use the .php extension, and access the file using your browser's localhost
1

#5 User is offline   garym 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 12
  • Joined: 12-January 12
  • Reputation: 0

Posted 23 January 2012 - 09:38 PM

View PostJay Gilford, on 23 January 2012 - 09:37 PM, said:

Have you set a webserver up on your local machine? or are you using hosting to test this?
If you haven't set up a webserver, I'd recommend WAMP or XAMPP for windows. html is not parsed as PHP. to parse php, you need to use the .php extension, and access the file using your browser's localhost



Ah, thanks. I'm using WAMP on my computer and accessing the file using: http://localhost/php...ox/logical2.php

:)
0

#6 User is offline   Jay Gilford 

  • Web Guru
  • PipPipPipPipPip
  • Group: Members
  • Posts: 1,105
  • Joined: 11-October 09
  • Reputation: 185
  • Gender:Male
  • Experience:Web Guru
  • Area of Expertise:Web Developer

Posted 23 January 2012 - 09:39 PM

And you're getting no output whatseover? Is the title showing in the browser at least?
1

#7 User is offline   garym 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 12
  • Joined: 12-January 12
  • Reputation: 0

Posted 23 January 2012 - 09:42 PM

View PostJay Gilford, on 23 January 2012 - 09:39 PM, said:

And you're getting no output whatseover? Is the title showing in the browser at least?


Yes, and looking in the source the statement "a is not 0,1 or 2" shows too.
0

#8 User is offline   Jay Gilford 

  • Web Guru
  • PipPipPipPipPip
  • Group: Members
  • Posts: 1,105
  • Joined: 11-October 09
  • Reputation: 185
  • Gender:Male
  • Experience:Web Guru
  • Area of Expertise:Web Developer

Posted 23 January 2012 - 09:43 PM

Ah, there's the issue then. The closing </title> is missing the <
1

#9 User is offline   garym 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 12
  • Joined: 12-January 12
  • Reputation: 0

Posted 23 January 2012 - 09:44 PM

View PostJay Gilford, on 23 January 2012 - 09:43 PM, said:

Ah, there's the issue then. The closing </title> is missing the <


Haha, I'm bloody stupid sometimes!

Thanks for helping me out. :)
0

#10 User is offline   Jay Gilford 

  • Web Guru
  • PipPipPipPipPip
  • Group: Members
  • Posts: 1,105
  • Joined: 11-October 09
  • Reputation: 185
  • Gender:Male
  • Experience:Web Guru
  • Area of Expertise:Web Developer

Posted 23 January 2012 - 09:45 PM

No problem. easy mistake to make. I'd recommend getting an IDE like phpDesigner that auto closes your tags for you. It's what I use, very helpful
1

#11 User is offline   garym 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 12
  • Joined: 12-January 12
  • Reputation: 0

Posted 23 January 2012 - 09:46 PM

View PostJay Gilford, on 23 January 2012 - 09:45 PM, said:

No problem. easy mistake to make. I'd recommend getting an IDE like phpDesigner that auto closes your tags for you. It's what I use, very helpful


Thanks, I'll look into that.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users