-5

When I am using

$_SESSION['$name'] = '$name';

I am getting the desired result, but when I am using

$_SESSION['$name'] = 'name';

OR

$_SESSION['name'] = '$name';

I am not getting desired result!

Is this the right way in which I am getting the desired result???

4

2 回答 2

1

感谢 OrangePill,因为我没有看到错误。

答案是:

这些都不是正确的。

$_SESSION['name'] = $name;

您已经创建了一个变量$name

您可以通过使用$namename获取值'name'

例如

$fname=$_POST['fname'];

我已经创建了变量$fname

<form>
 <input class="input" type="text"  name="fname" id="fname"  />
</form>

我从名为 的输入字段或元素中获取值$fname(在本例中为用户输入的名字,作为字符串),name="fname"我需要在 php 中将其格式化' '为 as 'fname'

于 2013-06-30T06:06:28.550 回答
1

你应该使用

$_SESSION['name'] = $name;

PHP中,变量插值(将变量扩展到那里的值)不会出现在单引号字符串中。

例如,

$name = 'user2534211';

echo '$name'; // will print $name

echo $name; // will print user2534211
echo "$name"; // will print user2534211;
于 2013-06-30T06:15:49.423 回答