2

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!!

4
  • 1
    do u have php? :O Commented Oct 19, 2016 at 9:13
  • Did you run this by entering a url in the browser or by double clicking the filename in explorer? Commented Oct 19, 2016 at 9:14
  • Do you have a web server? Does the web server have PHP configured Commented Oct 19, 2016 at 9:15
  • Are you using a local webserver (on your PC) or are you using a hosted server Commented Oct 19, 2016 at 9:18

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

if I am just using the PHP on my computer for this course, not as a web server, should I download a full suite like XAMPP?
I know that you want to start right now but maybe you should check a little tutorial to xampp and webservers first (Why you need them and what you can do with them). blog.udemy.com/xampp-tutorial check the steps if you want to go ahead with your tutorial skip the explanations but I recommend you to read everything ;)
1

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>

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.