host_255
host_255

Reputation: 361

PHP File not printing HTML form content

I am taking an HTML5 Tutorial on YouTube. Part of the course discussing CSS3 and PHP.

In the PHP section, the instructor provides the following code to print the form input to the screen:

    <?php

    $usersName = $_GET['name'];
    $usersPassword = $_GET['password'];

    echo 'Hello ' . $usersName . '<br>';
    echo 'That is a great password ' . $usersPassword . '<br>';

    ?>

The HTML it refers to is:

        <form method="GET" action="phpscript.php">
            Your Name: <input type="type" name="name" size="50" maxlength="50"><br>
            Your Password: <input type="password" name="password"><br>
            Your history:<br>
            <textarea name="history" rows="20" cols="50">Just random words</textarea>
            <input type="submit" name="submit" value="Submit">
            <input type="reset" value="Reset">
        </form>

The PHP variables do not print to the page. This is the output:

echo 'That is a great password ' . $usersPassword . '<br>';

I double checked what the instructor had in the video, and it is exactly the same. Then, I opened the Console in Firefox and I saw an error on the PHP page that said that the doctype and character encoding was not declared. In the instructions, the instructor has a php file with only php code in it. So, I got rid of those two errors by using my html file as a template and adding the php code between my <main></main> tags, but got the same output. So, I added <script type="text/php"></script> around the php code, then nothing printed.

Please help me so I can continue moving forward in this tutorial. The instructor was using a Mac and Chrome and running the files locally. I am running everything locally in Windows 7 and Firefox. I tested things out using IE and Chrome but got the same results.

Thank you!!

Upvotes: 2

Views: 1771

Answers (3)

Vinay
Vinay

Reputation: 7676

For just startup you don't need a fully fledged web server , you can use PHP's inbuilt server simply go in php's installation directory save your php then bring a command prompt on this directory and run

php -S localhost:80

Now access file using http://localhost/file.php You need to keep the shell open as long as you are using php

Upvotes: 1

cais
cais

Reputation: 13

You want to output the script without running it?

Try <xmp></xmp>

For example, if you want to print a link like this, it will look like this:

<a href="http://google.com">Google</a>

Google

but with the <xmp> tag, it looks like this:

<a href="http://google.com">Google</a>

Upvotes: 1

Johannes
Johannes

Reputation: 105

Sounds to me like either you do not have php running anywhere (Since it is server side you need a server to run it and I recommend XAMPP for this use) or your file has the ending .html but you would need a .php to run php code. Just putting it in between the <main> tag won't work.

Upvotes: 2

Related Questions