drp935159 2011-01-30 16:10
浏览 13

MYSQL更新值识别

I am doing an update script for a form. When user information is submitted on sign up its submitted to the user db with the following fields, username, pass, full_name and telephone. When the user updates the form to change his/her name for example, the username, pass, tele fields are also a part of the update form. So when a user updates his or her telephone # on the update form, the username info and pass info and the name info are also present on the form. The issue is that the system recognizes that the username is already taken.

So how do i update my script in such a way that the values changed should be picked up by the system. Or is there a better way to do this?

Code:

          if (!get_magic_quotes_gpc()) {
           $_POST['username'] = addslashes($_POST['username']);
       }
        $idcheck = $_POST['username'];
        $check = mysql_query("SELECT username FROM users WHERE username = '$username'")
          or die(mysql_error());
        $check2 = mysql_num_rows($check);


         if ($check2 != 0) {
         print("username already taken");
         die('');
           }

Basically the issue is that it recognizes that the values already exist but it doesn't realize that its the same users info not some other user using a common id or username...

  • 写回答

2条回答 默认 最新

  • drpiqlzrh62917192 2011-01-30 16:17
    关注

    Just remove the following code from the update script:

    $idcheck = $_POST['username'];
    $check = mysql_query("SELECT username FROM users WHERE username = '$username'") or die(mysql_error());
    $check2 = mysql_num_rows($check);
    
    if ($check2 != 0) {
       print("username already taken");
       die('');
    }
    

    And things should be fine then.

    If you have the same script for signing up and updating, I suggest you make two different scripts as that is a better practice.

    Best, Kamran

    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c