tags:

views:

44

answers:

3

i m working in PHP since one year, but now a days i got this way to assign post data value directly using name attribute . i m really curious to know the documentation about it.please refere me link regarding this .

i explain by example

here is my form

<form method="post" action="">
<input type="text" name="userName" id="userName">
<input type="submit" name="doit" value="submit">
</form>

to get the post data i always use

$somevar=mysql_real_escape_string($_POST['userName']);

but now i see another way

$somevar= "userName";

i just want to know that is it safe n easy way??

+1  A: 

Personally I like to use an escape function. So I would stick with mysql_real_escape_string()

I've never seen any code where a variable has been assigned from a quoted value. The way I understand it, all you'd be doing is making $somevar contain a string userName

DavidYell
I completely agree with u sir, but i seen this method, that's why i fire this question.even `register_globals` is off in php
diEcho
A: 

I think you're looking for the PHP ini directive register_globals. Take a look at Variables From External Sources. However, this directive defaults to "off" and you should probably leave it that way since it is deprecated in PHP 5.3. You would still have to mysql_real_escape_string() it anyway.

You can also use import_request_variables() to register the globals manually:

import_request_variables("p");
echo $userName;

Using Register Globals on the PHP website gives you a good idea as to how it can be unsafe to automatically register HTTP variables as globals.

Andy E
A: 

you can better use the below one

$somevar= $userName;
OR
$somevar= $_POST[userName];
VAC-Prabhu
i m not asking which one i have to use? i m asking that is it right way( 2'nd one)
diEcho
Yes, of course you can...
VAC-Prabhu
sorry! i m just asking that hev u ven seen the method 1? if yes then provide me any documentation regarding that
diEcho