PHP beginner 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
rozkan
Forum Newbie
Posts: 10
Joined: Thu Jul 02, 2009 8:08 pm

PHP beginner help

Post by rozkan »

Hello, i just started to learn PHP and using a book (6 years old) to learn it, there's some code examples and i've been coding according to these examples today i just wrote this code but it doesn't work. The code is exactly same as the example code but it just doesn't work, can somebody help me? Here's the code:

Code: Select all

<html>
<head>
<title>Hello!</title>
</head>
<body>
<?php 
if (empty($userName)) { 
echo <<<HERE
<form>
Please enter your username:
    <input type = "text"
        name = "userName"> <br/>
    <input type = "submit"
        input value = "Enter">
</form>
HERE;
}
else {
echo "Hello $userName";
}
//end 
?>
</body>
</html>
Thanks!
Last edited by califdon on Thu Jul 02, 2009 11:20 pm, edited 1 time in total.
Reason: Moderator added proper tags to display PHP
DagasSiren
Forum Newbie
Posts: 4
Joined: Thu Jul 02, 2009 4:12 pm
Location: Warren Indiana USA
Contact:

Re: PHP beginner help

Post by DagasSiren »

first off your not using method="POST" or action="$username" in your form declaration...

try looking at form declarations at: http://www.tizag.com/phpT/examples/formvar.php

hope this helps :) :)
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: PHP beginner help

Post by califdon »

In addition to the missing parameters for the <form ...> tag, you haven't retrieved the $username from the $_POST array. That's not an automatic assignment, you have to have code such as the following:

Code: Select all

if(isset($_POST['username'])) {
   $username=$_POST['username'];
}
There's more to it than that, namely, if you are going to do anything useful with the $_POST array data, like insert or update a database, it is very important to "sanitize" the data to protect your system from a hacker using SQL injection. But I don't want to confuse you at this point. Just remember that the above is only the first step.
Post Reply