Page 1 of 1

newbie question about $REQUEST_METHOD

Posted: Thu Jun 01, 2006 10:45 pm
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();
}
?>

Posted: Thu Jun 01, 2006 11:26 pm
by feyd
forgot a $ on the variable. ;)

Posted: Thu Jun 01, 2006 11:39 pm
by Christopher
A better check is:

Code: Select all

if (!strcasecmp($_SERVER['REQUEST_METHOD'], 'POST')) {