Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用数据库中的另一个字段名启动会话?_Php_Mysql_Phpmyadmin_Mysql Error 1064 - Fatal编程技术网

Php 如何使用数据库中的另一个字段名启动会话?

Php 如何使用数据库中的另一个字段名启动会话?,php,mysql,phpmyadmin,mysql-error-1064,Php,Mysql,Phpmyadmin,Mysql Error 1064,我在我的网站上注册了一个名为“name”的会话。这是我数据库中的一个字段,在一个人登录到多个登录屏幕中的一个部分后注册为会话。如何更改此会话变量?我的代码如下: <?php $secret_anwser=$_POST['secret_anwser']; $secret_anwser = stripslashes($secret_anwser); $secret_anwser = mysql_real_escape_string($secret_anwser); $sql="SE

我在我的网站上注册了一个名为“name”的会话。这是我数据库中的一个字段,在一个人登录到多个登录屏幕中的一个部分后注册为会话。如何更改此会话变量?我的代码如下:

    <?php

$secret_anwser=$_POST['secret_anwser'];
$secret_anwser = stripslashes($secret_anwser);
$secret_anwser = mysql_real_escape_string($secret_anwser);

$sql="SELECT * FROM public WHERE secret_anwser ='$secret_anwser' AND active = 'activated' AND name = '". $_SESSION['name']."'";

$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);

if($count==1){

header("location:votenow.php");
}
?>

不确定您所说的注册是什么意思,如果您仍在使用session\u register(),您不应该这样做。只要在页面上声明了会话(会话\u开始),就可以直接读取和写入$\u会话数组

作为对注释的响应-这与更改任何变量的原因相同

$_SESSION['xxxx']='yyyyy';

有大量关于php和如何使用的信息

您是否正在使用session_register()?是的,我正在使用session_register(),请参见下文,您不应该担心该函数已贬值,请参见手动输入。yh但如何将会话从“name”更改为“ni”?代码是什么…哈哈,我没有解释清楚。基本上,从上一页开始,iv传递了这个会话变量“name”。现在我不想把同一个变量传递到votenow.php,看到上面的代码是一个秘密的选择语句,即使我的sql语句没有提到任何关于ni的内容,我怎么可能让一个名为“ni”的字段成为我的新会话?如果ni是db的公共表中的一个字段名,那么您只需使用上面查询的值填充会话数组。好的,谢谢。我还有最后一个问题。这与会话变量或任何东西无关。我有一个if和else语句,我想在else位的echo部分执行一个select查询。可能吗?“在回显部分执行select查询”毫无意义,您可以根据条件执行查询,并根据相同条件在查询之前或之后回显某些内容;至少我认为这是你要问的