php mysql 值是否存在,PHP MySql-检查值是否存在

Need to check if both the EMAIL_ADDRESS and ACTIVATION_CODE exist within a MySql Table, if so return "Code is valid",else "Code is NOT valid".

At present it's always returning code not valid, however I've checked the record in the table and the queried code does exist.

$email = $_POST['email'];

$acticode = $_POST['code'];

$result = mysql_query("SELECT * FROM xActivate WHERE EMAIL_ADDRESS='$email' AND ACTIVATION_CODE='$acticode' LIMIT 1");

if (mysql_fetch_row($result)) {

echo 'Code is valid';

} else {

echo 'Code is NOT valid';

}

解决方案

But this code is not secure:

$email = $_POST['email'];

$acticode = $_POST['code'];

$result = mysql_query("SELECT * FROM xActivate WHERE EMAIL_ADDRESS='$email' AND ACTIVATION_CODE='$acticode' LIMIT 1");

$data = mysql_fetch_row($result);

if (mysql_num_rows($result) > 0) {

echo 'Code is valid';

} else {

echo 'Code is NOT valid';

}

To secure and prevent SQL Injection:

$email = mysql_real_escape_string($_POST['email']);

$acticode = mysql_real_escape_string($_POST['code']);

Please note:

Warning

This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQL extension should be

used. See also MySQL: choosing an API guide and related FAQ for more

information. Alternatives to this function include:

mysqli_real_escape_string()

PDO::quote()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值