Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10

Thread: PHP Problems

  1. #1
    New to the CF scene
    Join Date
    May 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP Problems

    Hello.

    I use NotePad++ for my general coding, but I have a problem. My PHP code wont work.

    PHP Code:
    <!DOCTYPE html>
    <html>
    <head>
        <title>Home</title>
    </head>
    <body>
    <?php
        $welcome 
    "Welcome To The Website";
        echo 
    $welcome;
    ?>
    </body>
    </html>
    The code wont show up in my browser.
    Help!

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    is the file saved as .php and is your server configured to parse .php files ?
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #3
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,899
    Thanks
    15
    Thanked 226 Times in 226 Posts
    One problem you may have is EOL ( end of line ) characters, which are different for Windows and 'nix machines.

    You may just need to get an app to change EOL characthers, or change your editor choice for them.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Quote Originally Posted by DrDOS View Post
    One problem you may have is EOL ( end of line ) characters, which are different for Windows and 'nix machines.

    You may just need to get an app to change EOL characthers, or change your editor choice for them.
    EOL has no impact on PHP code. Definition of instructions are controlled by the use of semi-colon delimiters in PHP, and some requirements for whitespace (such as 'function x'). Linefeeds themselves are only annoying between systems when using flat editors such as notpad or vi which interpret the spaces differently making reading tough.
    In other words, this is perfectly valid PHP code:
    PHP Code:
    class Car { private $make; private $model; public function __construct($make$model) { $this->make $make$this->model $model; } public function getMake() { return $this->make; } public function getModel() { return $this->model; } public function setMake($make) { $this->make $make; } public function setModel($model) { $this->model $model; } } $fouscar = new Car("Bugatti""Veyron"); printf("Fou-Lu's car is a %s %s :]" PHP_EOL$fouscar->getMake(), $fouscar->getmodel()); 
    The simplest thing the OP can do is simply open the HTML source on their browser. If they see <?php . . . ?> within it, than there is no preprocessing occurring.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #5
    New to the CF scene
    Join Date
    May 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    EOL has no impact on PHP code. Definition of instructions are controlled by the use of semi-colon delimiters in PHP, and some requirements for whitespace (such as 'function x'). Linefeeds themselves are only annoying between systems when using flat editors such as notpad or vi which interpret the spaces differently making reading tough.
    In other words, this is perfectly valid PHP code:
    PHP Code:
    class Car { private $make; private $model; public function __construct($make$model) { $this->make $make$this->model $model; } public function getMake() { return $this->make; } public function getModel() { return $this->model; } public function setMake($make) { $this->make $make; } public function setModel($model) { $this->model $model; } } $fouscar = new Car("Bugatti""Veyron"); printf("Fou-Lu's car is a %s %s :]" PHP_EOL$fouscar->getMake(), $fouscar->getmodel()); 
    The simplest thing the OP can do is simply open the HTML source on their browser. If they see <?php . . . ?> within it, than there is no preprocessing occurring.
    So want should I do to fix this?

  • #6
    New Coder
    Join Date
    Sep 2011
    Posts
    32
    Thanks
    1
    Thanked 0 Times in 0 Posts
    What are you saving your page as? and does your server support php?

  • #7
    New to the CF scene
    Join Date
    May 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by leest View Post
    What are you saving your page as? and does your server support php?
    I saved it as .php. But I don't use a server, I just push launch in chrome. Should I use a server instead?

  • #8
    New Coder
    Join Date
    Sep 2011
    Posts
    32
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Yes, unless you have something like wamp installed on your pc, you need a server to process the php. PHP is a server side language and so it will not run locally in browser

  • #9
    New to the CF scene
    Join Date
    May 2013
    Location
    Mohali,India
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you need to have wamp , xamp installed in your system

  • #10
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,091
    Thanks
    51
    Thanked 506 Times in 493 Posts
    As others have said, you need to run a wamp system such as the uniformserver or xampp (there are many different wamp setups - wamp is a generic name).

    You don't usually need to install wamp as most wamp setups will just run from the folder they're in (or a usb drive for the ultimate in portability!).

    When you have your wamp system downloaded and running, you then call your script via the localhost loopback address like this:

    http://localhost/script.php

    What happens then is that your webserver will then open the file, pass it to the php program which will then execute the php code. PHP will then pass back the results to the webserver which will then send it to your browser. This is why you cannot simply open a php file in your browser directly.
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!


  •  

    Posting Permissions

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