Jump to content

Form not working

Whether you're a seasoned veteran or a struggling beginner, Web Radiance is the web development and web design forum for you. You'll find answers to all your HTML, CSS, SEO, and Programming needs. Pull up a chair and stay awhile.

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

Form not working Rate Topic: -----

#1 User is offline   Matthean 

  • W.R. Private
  • Group: Members
  • Posts: 18
  • Joined: 15-October 07

Posted 15 January 2009 - 10:39 AM

I even went and grabbed the code that came with the book and the author's version isn't working either. Offhand not seeing anything that sticks out as being wrong. The post variables seem to be obviously not getting passed as it always displays the form.

<?php
// create short names for variables
$name	 = $POST['name'];
$password = $POST['password'];

if (empty($name) || empty($password)) {
	// Visitor needs to enter a name and password
?>
	<h1>Please Log In</h1>
	This page is secret.
	<form method="post" action="secret.php">
		<table border="1">
			<tr>
				<th>Username</th>
				<td><input type="text" name="name" /></td>
			</tr>
			<tr>
				<th>Password</th>
				<td><input type="password" name="password" /></td>
			</tr>
			<tr>
				<td colspan="2" align="center">
					<input type="submit" value="Log In" />
				</td>
			</tr>
		</table>
	</form>
<?php
	}
	else if ($name=='user'&&$password=='pass') {
		//visitor's name and passowrd combination are correct.
		echo '<h1>Here it is!</h1>';
		echo 'I bet you are glad you can see this secret page.';
	}
	else {
		//visitor's name ansd password combination are not correct
		echo '<h1>Go Away!';
		echo 'You are not authorized to view this resource.';
	}
?>

0

#2 User is offline   Karl Buckland 

  • A.K.A. Sirkent
  • Group: Administrators
  • Posts: 2,145
  • Joined: 04-April 06
  • Gender:Male
  • Location:Kent, UK

Posted 15 January 2009 - 11:03 AM

This:
$POST['name'];
is not valid!

You need to use:
$_POST['name'];


It's quite worrying that a book would contain such a fundamental error...
QUOTE(benbramz @ Aug 17 2007, 07:44 AM) Ive noticed that quite a few people are now adding quotes from the board into their signature. I think its started an new web-radiance craze.. :P
0

#3 User is offline   Matthean 

  • W.R. Private
  • Group: Members
  • Posts: 18
  • Joined: 15-October 07

Posted 15 January 2009 - 09:53 PM

View PostSirkent, on Jan 15 2009, 12:03 PM, said:

This:
$POST['name'];
is not valid!

You need to use:
$_POST['name'];


It's quite worrying that a book would contain such a fundamental error...



Actually, the missing underscore was my error. The book's downloaded version of the code doesn't even use the POST variables. It was just using this...

if(!isset($name)&&!isset($password))


Which again, didn't seem to work.

I do have two different editions of the same book, so I'm wondering if the CD I grabbed the code from was from the older edition.
0

#4 User is offline   Karl Buckland 

  • A.K.A. Sirkent
  • Group: Administrators
  • Posts: 2,145
  • Joined: 04-April 06
  • Gender:Male
  • Location:Kent, UK

Posted 16 January 2009 - 04:00 AM

Possibly - just using $name involves having PHP's register_global's setting set to 'on', which has been regarded as a dangerous thing to do for the past several years.
QUOTE(benbramz @ Aug 17 2007, 07:44 AM) Ive noticed that quite a few people are now adding quotes from the board into their signature. I think its started an new web-radiance craze.. :P
0

#5 User is offline   haku 

  • 日本語 Ninja
  • Group: Members
  • Posts: 652
  • Joined: 21-September 07
  • Gender:Male
  • Location:Yokohama, Japan

Posted 17 January 2009 - 08:35 AM

And on that note, I would recommend scrapping that book. Any book that is relying on outdated, non-secure methods is probably not a good book to be learning from.
<a href="http://www.jaypan.com" target="_blank">Jaypan</a>
<a href="http://www.dudes-japan.com" target="_blank">Dudes Japan</a>
0

#6 User is offline   Matthean 

  • W.R. Private
  • Group: Members
  • Posts: 18
  • Joined: 15-October 07

Posted 17 January 2009 - 04:51 PM

View Posthaku, on Jan 17 2009, 08:35 AM, said:

And on that note, I would recommend scrapping that book. Any book that is relying on outdated, non-secure methods is probably not a good book to be learning from.


FYI, the book is "PHP and MySQL Web Development" which generally gets great reviews. I actually just looked up the old version of the book(2nd ed., 2003) I have and found out that's the CD I used for the code archive. I somewhat moved recently so I have no idea where the CD for the more current book(3rd ed.) is at. The publisher doesn't have a downloadable code archive either.
0

#7 User is offline   Karl Buckland 

  • A.K.A. Sirkent
  • Group: Administrators
  • Posts: 2,145
  • Joined: 04-April 06
  • Gender:Male
  • Location:Kent, UK

Posted 19 January 2009 - 04:49 AM

It was a good book when I used it - about 5 years ago. Now I wouldn't be so sure, but if you read up on the newer methods and security suggestions then I think you'll be fine.
QUOTE(benbramz @ Aug 17 2007, 07:44 AM) Ive noticed that quite a few people are now adding quotes from the board into their signature. I think its started an new web-radiance craze.. :P
0

#8 User is offline   EncoderDecoder 

  • W.R. Sergeant
  • Group: Members
  • Posts: 260
  • Joined: 01-March 11
  • Gender:Female
  • Location:Philippines

Posted 02 March 2011 - 09:50 PM

First, its $_POST.. not $POST..
0

#9 User is offline   Smith01 

  • W.R. Private
  • Group: Members
  • Posts: 3
  • Joined: 12-March 11

Posted 14 March 2011 - 01:05 AM

Your support is much appreciated.
It works now !!!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users