$query='Select * from users where userid="'.$_POST['userid'].'"';

I tend to use single quotes whenever I can and to use concatenation instead of using in-string variables. I do this for three reasons. The first is efficiency. Strings surrounded by single chars are not parsed for any values, such as variables and backslashed characters (except for '). This saves in execution time every time the script is executed. It also helps with readability of the code as some syntax highlighting doesn't catch variables in strings. The last reason is that I know exactly what the code is going to do. I never really know what will be used as the variable when I do it in a string. Will it follow a ->? What about two? I don't always know and it's easier to debug without all of the extra hassle.

Pete M wrote:
$query="Select * from users where userid='".$_POST['userid']."'";

;-)
pete

Luis Lebron wrote:

This may be a dumb question but here goes. I have been trying to use $_POST
globals in sql queries.
If I use the following query string it does not work
$query="Select * from users where userid='$_POST['userid']'";


However, this works
$userid=$_POST["userid"]
$query="Select * from users where userid='$userid'";

Is there a mistake in my syntax?

thanks,


Luis R. Lebron Sigmatech, Inc


-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to