Home > Backend Development > PHP Tutorial > 关于账户激活的奇葩有关问题

关于账户激活的奇葩有关问题

WBOY
Release: 2016-06-13 12:13:18
Original
1240 people have browsed it

关于账户激活的奇葩问题,
请教大神我这段代码有什么问题,以前好好的 ,现在却出现莫名问题,编辑器是netbeans,也重新安装过.
现在运行时能执行到第二个_query函数,也就是对数据库的操作成功了,之后就跳过mysql_affected_rows()那段直接执行下面的 else {
_alert_back('非法操作');
}

<br />if (isset($_GET['active']) && $_GET['action'] === 'ok') {<br /><br />	$_active = _mysql_string($_GET['active']);<br /><br />  	if (mysql_fetch_array(_query("SELECT tg_active FROM tg_user WHERE tg_active='$_active' LIMIT 1"),MYSQL_ASSOC)) {<br /><br />         //将tg_active设置为actived<br />		_query("UPDATE tg_user SET tg_active='actived' WHERE tg_active='$_active' LIMIT 1");<br /><br />		if (mysql_affected_rows() == 1) {<br /><br />			mysql_close();<br /><br />			_location('账户激活成功','login.php');<br /><br />		} else {<br /><br />			mysql_close();<br /><br />			_location('账户激活失败','register.php');<br />		}<br />	} else {<br /><br />		_alert_back('非法操作');<br />	}<br />}<br />
Copy after login


------解决思路----------------------
检查了一下你的代码,应是
if (mysql_fetch_array(_query("SELECT tg_active FROM tg_user WHERE tg_active='$_active' LIMIT 1"),MYSQL_ASSOC))
此段就发生问题,你确定有执行到_query阶段

<br />if (mysql_fetch_array(_query("SELECT tg_active FROM tg_user WHERE tg_active='$_active' LIMIT 1"),MYSQL_ASSOC)) {<br /> <br />         //将tg_active设置为actived<br />        _query("UPDATE tg_user SET tg_active='actived' WHERE tg_active='$_active' LIMIT 1");<br /> <br />        if (mysql_affected_rows() == 1) {<br /> <br />            mysql_close();<br /> <br />            _location('账户激活成功','login.php');<br /> <br />        } else {<br /> <br />            mysql_close();<br /> <br />            _location('账户激活失败','register.php');<br />        }<br />    } else {<br /> <br />        _alert_back('非法操作');<br />    }<br />
Copy after login

------解决思路----------------------
就你贴出的代码而言,是不可能出现你说的情况的
因为
_query("UPDATE tg_user SET ....

_alert_back('非法操作');
分属
if (mysql_fetch_array(_query("SELECT tg_active FROM... 
的两个分支
不可能同时被执行!
因此,可以认为你实际运行的不是这段代码

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template