User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 374,048 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,913 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 3110 | Replies: 5
Reply
Join Date: Apr 2004
Posts: 3
Reputation: Impassible is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Impassible Impassible is offline Offline
Newbie Poster

BASIC FORM problems...

  #1  
Apr 20th, 2004
hello.. I am just testing a simple PHP password/verify form... and I don't know why its not working. I am new to PHP but I have looked at other sample codes and mine seems to be okay in my eyes...
I have two files... password.html and password.php.

password.html looks like this:
<html>
<head>
<title> Password Script </title>
</head>
<body>
<center>
<form name="form1" method="post" action="password.php">
<input name="username" type="text" id="username">
<p>Enter your First Name Please</p>
<input type="submit" name="Submit" value="Submit">
</form>
</center>
</body>
</html>


and password.php looks like this:

<?php
if ($username == "Rob")
{
print "Yay, Rob you are logged in!";
}
else
{
print "I am sorry the password is incorrect. Please go back and try again";
}
?>


Now when I enter Rob as the name, i STILL get "I am sorry the password is incorrect. Please go back and try again" ... I don't understand why this is happening. No matter what I put as the password in the form, I still get the I am sorry message. Please help... this is probably something really simple but I'm just too new at this to catch it. The server is running PHP 4.3.4 and is hosted with OSX Panther Server 10.3.

I just want to be able to create small password frms, where someone can enter a password and proceed to the next page.
try it for yourself http://www.impassible.com/documents/.../password.html

Thanks alot...
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2003
Location: London, England
Posts: 281
Reputation: Roberdin will become famous soon enough Roberdin will become famous soon enough 
Rep Power: 7
Solved Threads: 6
Colleague
Roberdin Roberdin is offline Offline
Supreme Evil Overlord

Re: BASIC FORM problems...

  #2  
Apr 20th, 2004
Well it's no doubt because the server administrator is sane.

Try changing $username to $_POST['username']. By default PHP won't assign external variables passed through forms, cookies, and URLs for security reasons. It's pretty obvious why - otherwise, anyone who had seen the script (or who hadn't and was just guessing) could add something like &admin=1 or something and find themselves granted admin access. Additionally, it means that you can tell where the varibales came from - be a form ($_POST), a URL ($_GET), or a cookie ($_COOKIE).

Note, however, that if your form's method is set to get instead of post, that you'll need to retreive the variable through $_GET. But this will rarely, if ever, be an issue.
Reply With Quote  
Join Date: Apr 2004
Posts: 3
Reputation: Impassible is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Impassible Impassible is offline Offline
Newbie Poster

Re: BASIC FORM problems...

  #3  
Apr 21st, 2004
Thanks alot, that worked perfectly! As simple as that is it will help me out a lot.

can I ask one more thing?
I am reading the book "Teach yourself PHP in 24 hours"... is a pain in the ass for me because I am dyslexic but I am forcing myself to learn cause PHP is wonderful... I have gotten to hour 8, and one thing it never explained to me in a logical way (at least I never grasped it) was what "as" means/does. Its been used since the earlier hours of the book, but I have just been using it not really knowing exactly what it means. Can you give me a good explination so that from now on, when I use it, I'll know why?
example...


foreach ($first as $key=>$val)

thanks in advance!
Reply With Quote  
Join Date: Feb 2003
Location: London, England
Posts: 281
Reputation: Roberdin will become famous soon enough Roberdin will become famous soon enough 
Rep Power: 7
Solved Threads: 6
Colleague
Roberdin Roberdin is offline Offline
Supreme Evil Overlord

Re: BASIC FORM problems...

  #4  
Apr 21st, 2004
ok, have you covered arrays? I will assume you have for the moment. Otherwise, the following will only confuse you. :p

AFAIK, as is only used in a foreach() statement.

Let's say that you have an array of people's names and that you want to correctly capitalise each name (for the moment we'll exclude Scottish People who are McSomething for simplicty).

One way of doing it, would be as follows.

[PHP]
/* The names are defined below. I prefer to write arrays out like that to ensure they're easy to read, but the format is up to personal preference. Because you may have a different monitor size to me, I'm using /* instead of // to comment. (So you can see that all this is actually supposed to be one line) */

$people = array(
'JAsmine',
'cROwsteN',
'sylvester',
'aPple',
'Snoopy'
);

/* Next, we want to look at each item in the list and correct the capitialisation. */

foreach( $people as $person )
{
/* What's happened here? Well, this is a special kind of loop that loops through each item in the array $people, and assigns the value each time to $person. So, the first time this loops, $person will be equal to 'JAsmine'. The next; 'cROwsteN', and so forth. */

echo '<br />Person: ' . ucfirst(strtolower($person));

/*That essentially turns the value of $person to completely lower case (strtolower) and then changes the first letter to upper case (ucfirst), the echos it following '<br />Person: '. */
}
[/PHP]

Ok, now, suppose for some reason, you want to actually know which index that person had and echo that along with it? Well, you can do a similar thing like so:

[PHP]
$emails = array(
'bob' => 'bob@bobby.com',
'rob' => 'rob@rob.com',
'me' => 'me@you.com'
);

foreach( $emails as $name => $email )
{
echo "{$name}'s email is $email. <br />";
}
[/PHP]

Will echo something like:
bob's email is bob@bobby.com
rob's email is rob@rob.com
etc...

I hope that clears up any confusion.
Reply With Quote  
Join Date: Apr 2004
Posts: 3
Reputation: Impassible is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Impassible Impassible is offline Offline
Newbie Poster

Re: BASIC FORM problems...

  #5  
Apr 21st, 2004
Thanks! That explained it pretty well. Much better than the book. It all makes sense now.
Reply With Quote  
Join Date: Feb 2003
Location: London, England
Posts: 281
Reputation: Roberdin will become famous soon enough Roberdin will become famous soon enough 
Rep Power: 7
Solved Threads: 6
Colleague
Roberdin Roberdin is offline Offline
Supreme Evil Overlord

Re: BASIC FORM problems...

  #6  
Apr 21st, 2004
Books can only take you so far, and they're often quite outdated - though I'm surprised that it's assuming request (sent in forms, urls, cookies) variables have been assigned to normal variables automatically. It's been default not to since PHP4, and the PHP people have been blathering on about it since early PHP3.

But anyway, just come back here if ya need any more help.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb PHP Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 12:31 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC