I've decided to recode all my variables on my pages as PHP 4.3 now demands they be (unless you have register_globals = on) as :
I'm doing this in advance in case any server I am on has register_globals = off (as is now recommended). Thus, using just $var_name is no longer sufficient to obtain its value. You must fetch the value as shown above.
The problem is, however, when doing things like a trim() on a variable, e.g. "FirstName" this will not obviously work :
$FirstName = trim(\"$_POST['FirstName']\");
Nor will :
$FirstName = trim($_POST['FirstName']);
The trim() function seems to demand a string literal. The only way I can see around this issue is to do :
You should really just declare and initialize all of your variables anyways in the beginning and never try to do multiple things all in one line. That detracts from readability of the code.
For example this is more readable...
//Declare and Initialize POST data
$firstname = $_POST['first'];
$lastname = $_POST['last'];
//Remove whitespace from data
$firstname = trim($firstname);
$sql = "SELECT col FROM tablename WHERE yaks = '$firstname'";
$sql = "SELECT col FROM tablename WHERE yaks = 'trim($_POST['first']'";
Yes it takes a few more lines of code but will save you time or others time if you every have to go back to the code later on. Plus if you declare and initialize your variables in the beginning then if you ever needed to change the name of a form element or something then you won't have to go through the code looking for each occurence where you used it at. You would just need to change it at the beginning.
CodingForums Supreme Overlord
All Hail Spookster
Who gave you that Ugging infraction? Yeah that's right it was me!