0

I'm just learning PHP, and during the process of learning, the tutor asked me to create two files: a HTML file and a PHP file. The HTML file (named name.html) looks like this:

<!DOCTYPE html>
<html lang="en">

<head>
    <title> Today&rsquo;s Date </title>
    <meta name="viewport" content="width=device-width">
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>

<body>
    <a href="name.php?name=Kevin">Hi, I&rsquo;m Kevin!</a>
</body>

while the PHP file (named name.php) is this:

<!DOCTYPE html>
<html lang="en">

<head>
    <title> Today&rsquo;s Date </title>
    <meta name="viewport" content="width=device-width">
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>

<body>

    <?php
       $name = $_GET['name'];
       echo 'Welcome to our website, ' . $name . '!';
    ?>

</body>

Now the problem is this: the php file should output “Welcome to our website, Kevin!” after the link on the html file has been clicked according to the author. But mine doesn't, in fact it doesn't output anything at all.

I wonder if there is a problem with my code. Any php expert in the house should please put me through.

thanks.

Bas
  • 2,106
  • 5
  • 21
  • 59
Yusuf01
  • 27
  • 3
  • View source in browser. Do you see PHP code? If so then your PHP is not properly configured – Hanky Panky May 28 '15 at 07:47
  • what is the error code you are getting ? – Junaid May 28 '15 at 07:47
  • I think you haven't an PHP server running. – Alaanor May 28 '15 at 07:48
  • By any means are you just opening the PHP file as it is? It needs to be hosted on a web server and be served via `http / https`. Even if that webserver is on your local computer it has to be there – Hanky Panky May 28 '15 at 07:48
  • 1
    Are you testing them on your local machine? If so, unless you've got PHP running you won't be able to see the result of the code - and you'll see a blank page. Upload it to a web server that can run PHP. But in answer to your question, no there is nothing wrong with your code (except for the missing ` – Geoff Atkins May 28 '15 at 07:49
  • you need to put php file on web sever, you can install WAMP or XAMPP in your computer and then run your php file in it. – Raja Usman Mehmood May 28 '15 at 07:49

3 Answers3

0

It seems you don't have a PHP server running,

if you are on Windows, you should try WAMP (http://www.wampserver.com)

lucasgehin
  • 127
  • 2
  • 13
0

if you are running in localhost then you are url should be like

http://localhost/a.html

also make sure in wamp or xampp ,apache running or not.

0

You have to run this file under localhost (server). The reason why nothing appears in the browser is that by default browser would make <?php ... ?> as <!--?php ?--> if viewed without being parsed by the server.

Fix: View it on a server.

mehulmpt
  • 15,861
  • 12
  • 48
  • 88
  • I have xampp running... I run the code via my local server, both files are located in htcdocs file of xampp... – Yusuf01 May 28 '15 at 11:16
  • I opened other php files and they all opened (while xampp is running) it's only the name.php file that doesn't open, I checked for bugs (using firebugs) but couldn't find any – Yusuf01 May 28 '15 at 11:23
  • Check the source code of document (from browser). Does it have commented out PHP code? If not, then check the response header. Are you sure your URL points towards correct file? – mehulmpt May 29 '15 at 16:32
  • sorry I'm replying late... Yes I checked the source and I have the PHP code commented out in chrome... I wonder what the problem is? – Yusuf01 Jun 03 '15 at 08:09
  • Yeah @Yusuf01 that clearly signifies that you are running PHP file directly from browser instead of localhost. Your URL must also be something like `file:///` right now. Start XAMPP and go to `localhost/YOUR_FOLDER_IN_HTDOCS` and then it'd work. – mehulmpt Jun 03 '15 at 12:05
  • Thanks a lot, and that works... I was using "Ctrl + O" to open the file instead of using localhost/filename.php – Yusuf01 Jun 05 '15 at 08:08
  • @Yusuf01 Care to mark this answer as correct? :) – mehulmpt Jun 10 '15 at 17:46