Html call to PHP doesn't work

php

#1


A called PHP program used to work fine, now it doesn't.


The PHP program that is called does not execute properly. A simple print command will only print the variable name and not it's contents like it used to do. Also, anything past the variable name also is printed including control characters. The url shows file:///C:/xampp/htdocs/AskName1.php?userName=John. If I overwrite "file:///C:/xampp/htdocs/" with http://localhost/" it works fine?

This is the original result:                                                                   My name is $myName!"; ?> 

This is what it should look like and does when I overwrite url:          My name is John!


#2

The original result looks like this: My name is $myName!"; ?>


#3

php is a serverside language, if you just open the file with file://, it will just open the file. If you however use localhost, you access the xampp (guess you used xampp) webserver, which means the php code actually gets executed


#4

The html program call is using "file:///" and as a result the called PHP program is not executing properly?


#5

but browser are designed to open html files, so then you can use file://, they are not designed to open php code, that is done on server side. (which is why you need the http://localhost), you use this to visit the website, by making a request to a server (xampp is the server)

Server is just a fancy word for a (big) computer which host a website (called a webserver). In this case, your computer also hosts the website.


#6

My html code is below:

<!DOCTYPE html>
<html lang = "en-US">
<head>
    <meta charset = "UTF-8">    
    <title>askName.html</title>              
</head>     
<body>    
    <form action = "AskName1.php"
          method = "get">
        <fieldset>
            <label>Please enter your name</label>        
            <input type = "Text"
                   name = "userName" />
            <button type = "submit">
                submit
            </button>
        </fieldset>           
    </form>
</body>
</html>

The code for PHP is:

<!DOCTYPE html>
<html lang = "en-US">
    <head>
        <meta charset = "UTF-8">    
        <title>AskName1.php</title>          
    </head>    
    <body>        
        <?php
        $myName = filter_input(INPUT_GET, "userName");        
        print "<h1>My name is $myName!</h1>";    
        ?>        
    </body>
</html>

The result is: My name is $myName!"; ?>
url is: file:///C:/xampp/htdocs/AskName1.php?userName=John


#7

it is too late, i will look into tomorrow


#8

Thank you very much, I am very confused about how this is happening. Have a good night.....John


#9

i can't get php to work for some weird reason, i will briefly look into it

Right, i made a few changes, i renamed it to askname.php:

<!DOCTYPE html>
<html>
<head><title></title></head>
<body>
<?php
$myName = filter_input(INPUT_GET, "userName");
print "<h1>My name is $myName!</h1>";
?>
</body>
</html>

and it works fine, make sure php is running and working, include:

<?php phpinfo(); ?>

this should show a lot of info about php, if this won't show, your php isn't installed correctly.