PHP help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
someone2088
Forum Commoner
Posts: 42
Joined: Thu Nov 17, 2011 1:09 pm

PHP help

Post by someone2088 »

Hi, I'm trying to write some basic PHP to allow a user to enter their username in a website, and then maintain a session throughout, or until the user selects 'logout'. I've only done a very small amount of PHP in the past, and that was roughly two years ago, so any help would be much appreciated.

Basically, so far, I have two files: index.html and home.php

index.html looks like this:

Code: Select all

<html>
<body>

<form action="home.php" method="post">
Name: <input type="text" name="userName" />
<input type="submit" />
</form>

</body>
</html>


and home.php looks like this:

<html>
<body>

Welcome <?php echo $_POST["userName"]; ?>!

</body>
</html>
When I view index.html in the browser, I can enter a username into a text box, and click a 'submit' button. When I click the 'submit' button, I am taken to the 'home' page, which should display a message saying "Welcome <username> !"

However, at the moment, the 'home' page just displays "Welcome !"
Can anyone tell me what I'm doing wrong, and what I need to do to get the username to be displayed on the 'home' page, and any subsequent pages?

Thanks in advance!
Last edited by Benjamin on Thu Nov 17, 2011 2:20 pm, edited 1 time in total.
Reason: Added [syntax=php||htm||css||javascript||sql||etc] - Please use [syntax] tags when posting code in the forums! Thanks.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP help

Post by Celauran »

Have you confirmed that PHP is installed correctly and running?

Does this alone in a page display anything?

Code: Select all

<?php echo phpinfo(); ?>
someone2088
Forum Commoner
Posts: 42
Joined: Thu Nov 17, 2011 1:09 pm

Re: PHP help

Post by someone2088 »

If I put that in a blank text document and save it as .html, it displays a blank page in the browser. If I save it as .php, and display it in the browser, it just shows the text as it's written there.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP help

Post by Celauran »

You have to save PHP files as .php. If it's just displaying the PHP code in the browser, then PHP is not installed/configured correctly.
someone2088
Forum Commoner
Posts: 42
Joined: Thu Nov 17, 2011 1:09 pm

Re: PHP help

Post by someone2088 »

Thanks for your help with this. I've just installed PHP, but still seem to be having the same trouble- how do I check whether it's configured correctly?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP help

Post by Celauran »

Which version on which OS? You could probably get some help in the installation and configuration forum. Maybe ask a mod to move this.
someone2088
Forum Commoner
Posts: 42
Joined: Thu Nov 17, 2011 1:09 pm

Re: PHP help

Post by someone2088 »

I'm using Windows 7 Home Premium- happy to use whichever version works!
Post Reply