dongtu1958 2011-09-01 22:44
浏览 15
已采纳

有关如何继续验证注册用户和更新mySQL的代码的帮助

When a user registers, the script sends an email to verify his account. Clicking on the link, the script gets the token

$token = mysql_real_escape_string($_GET["token"]);

and what I thought to do is

if($token != '') {
mysql_query("UPDATE members SET verified = '' WHERE verified = '$token'");
}

or

if($token != '') {
    $result = mysql_query("UPDATE members SET verified = '' WHERE verified = '$token'");
    if($result) { }
    else { }
}

What is my purpose is to echo a success or failed message on the user. When it will be success then the verified will be empty.

What is the appropriate way of doing this with my examples above?

Should I check if there is the token in the DB before updating it?

Thank you.

  • 写回答

1条回答 默认 最新

  • duanmi3476 2011-09-01 22:51
    关注

    Your current method updates a record if it exists but does not take into account that which does not exist or match. You should run something similar to:

    if($token != '') {
        $result = mysql_query("SELECT COUNT(*) FROM members WHERE verified = '$token'");
    
        while($row = mysql_fetch_row($result)) {
           $records = $row[0];
        }
    
        if($records == 0) { echo 'no results'; }
        elseif($records ==1) { echo 'you matched'; then update the record. }
    }
    

    edit

    changed BACK to the while loop, wasn't thinking of the count returning 0 rows

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建