newbie question about $REQUEST_METHOD

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
tilda
Forum Newbie
Posts: 1
Joined: Thu Jun 01, 2006 10:23 pm

newbie question about $REQUEST_METHOD

Post by tilda »

Hi I'm totally new to PHP, it's an interesting langue, and I'm exited by the possibilities it holds. But I'm having trouble with my first script. I'm not sure if this is the right forum to be posting questions, and if it's not, I'd like to apologies for my error.

To the question. I'm trying to use the most basic forms. But I'm having trouble with REQUEST_METHOD; every time I try to compare it POST, it doesn't match, and I"m not sure why, any ideas?

He is the code I am using.

Code: Select all

<?php
function printForm()
			{
				// btw, userForm.php is the name of the file, is there a way to fetch the name of the file,
				// so I don't have to hard code the name of the file into the code?
				echo '
					<!-- form start -->
						<form action="userForm.php" method="POST" > 
							<fieldset>
								<legend>Define your search:</legend>
								<p><b>Name:</b>    <input type="text"  name="user_name"   size="20" maxlength="40" /></p>
								<div align="center"><input type="submit" name="submit" value="Find" /></div>
						</form>
					<!-- form end   -->
				';
			}

if ( $REQUEST_METHOD == 'GET' )
{
	printForm();
}
else if ( REQUEST_METHOD == 'POST' )
{
	// responce to form
}
else
{
	echo 'Error, invalid REQUEST_METHOD, \'', $REQUEST_METHOD, '\'';
	printForm();
}
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

forgot a $ on the variable. ;)
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

A better check is:

Code: Select all

if (!strcasecmp($_SERVER['REQUEST_METHOD'], 'POST')) {
(#10850)
Post Reply