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
SidewinderX
Forum Contributor
Posts: 407 Joined: Fri Jul 16, 2004 9:04 pm
Location: NY
Post
by SidewinderX » Sat Apr 22, 2006 4:23 pm
i cant seem to figure out why this isnt working, any ideas?
Code: Select all
<?php
if(empty($username))
{
echo "Enter Your Name:
<form method='POST' action=" . $_SERVER[PHP_SELF] . ">
<input type='text' name='username'>
<input type='submit' value='Log In'>
</form>";
}
else
{
echo "Hi " . $_POST[username] . "!";
}
?>
thanks-side.
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Sat Apr 22, 2006 4:27 pm
??
Also, remember to quote your array indices
Code: Select all
echo "Hi " . $_POST['username'] . "!";
andym01480
Forum Contributor
Posts: 390 Joined: Wed Apr 19, 2006 5:01 pm
Post
by andym01480 » Sat Apr 22, 2006 4:32 pm
Two mistakes I could see...
if empty needed $_POST
and $_SERVER['PHP_SELF'] needed quotes
Try
Code: Select all
<?php
if(empty($_POST['username']))
{
echo "Enter Your Name:
<form method='POST' action=" . $_SERVER['PHP_SELF'] . ">
<input type='text' name='username'>
<input type='submit' value='Log In'>
</form>";
}
else
{
echo "Hi " . $_POST['username'] . "!";
}
?>
Sorry to repeat, beat me to posting!!!!
timvw
DevNet Master
Posts: 4897 Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium
Post
by timvw » Sat Apr 22, 2006 10:21 pm
Better use
htmlentities to make sure the data is ready for use in html...
Christopher
Site Administrator
Posts: 13596 Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US
Post
by Christopher » Sat Apr 22, 2006 10:28 pm
Also remember that empty() matches a bunch of values ('', null, 0, false..) some of which may not be what you are looking for.
(#10850)
andym01480
Forum Contributor
Posts: 390 Joined: Wed Apr 19, 2006 5:01 pm
Post
by andym01480 » Sun Apr 23, 2006 2:01 pm
Does that mean isset() is better?