-1

Im trying to send 2 variables to my php page via a link, i can't figure out what im doing wrong. The outcome is not right. Im expecting just the display of values and instead the whole php code displays.

Thanks for helping in advance, below is my html, php and result.

My html page is named "index.html" and my php "default.php"

HTML:

<!DOCTYPE html>
<html lang="sv">
    <head>
  <title>Information sänd via adressfältet och länkar</title>
  <meta charset="UTF-8">
    </head>
    <body>
  <a href="default.php?name=filip&gender=man">Link</a>
    </body>
</html>

php:

<?php

 header("Content-Type: text/plain");
 
 echo $_GET["name"];
 echo $_GET["gender"];
 
?>

Result:

<?php

 header("Content-Type: text/plain");
 
 echo $_GET["name"];
 echo $_GET["gender"];
 
?>
Filip
  • 45
  • 7
  • That seems to be a problem with your server configuration not executing the php file, take a look here https://stackoverflow.com/questions/5121495/php-code-is-not-being-executed-instead-code-shows-on-the-page – Claudio Dec 18 '17 at 12:29
  • no error in above code.. – Bilal Ahmed Dec 18 '17 at 12:30
  • where are you running this code? Is it on a hosting server, a local wamp/xamp, or directly from a local folder? – Juan Dec 18 '17 at 12:33
  • Thanks @claudio that thread solved it for me <3 – Filip Dec 18 '17 at 12:50

2 Answers2

0

I found the problem thnx to this thread: PHP code is not being executed, instead code shows on the page

The problem was:

Make sure you are accessing your file over your webserver using an URL like http://localhost/file.php not via local file access file://localhost/www/file.php

Martin
  • 22,212
  • 11
  • 70
  • 132
Filip
  • 45
  • 7
0

There are a couple of factors affecting such first one confirm that your php module is properly configured to Apache and it reads the .php extension two that your file is actually saved as .php if you are using a text-editor like notepad which appends the .txt file format at the end, unless you select file type as all files

Ezekiel
  • 671
  • 5
  • 13