doutuo7126 2013-06-08 13:19
浏览 49
已采纳

$ _get无效

i created update code for updating password in a table using id.This is the url from where i am getting id using $_GET but its not working.

http://www.example.com/en/resetPaSS.php?id=1&token=779d2aa48de104db46d66e29de576aac

The code:

if(isset($_POST['sub']))
{
$pass_hash = PassHash::hash($_POST['pass']);

$sql = "UPDATE user SET password='$pass_hash' WHERE id='$_GET[id]'";
$resu = mysqli_query($link,$sql);
//echo $sql;
if(!$resu)
    {
     $error="Unable to change Password. Try Again!";
    }
    else
    {
     echo"changed";
    }
}

I also echo $sql and it shows UPDATE user SET password='$2a$10$bed9ad8e6cb910e0f1f12uXJldZLQ79f5HVrIiIAIZeZ9088Rre9.' WHERE id=''

Also tried $_REQUEST but still not works.

EDIT: I am using this url for reseting password to send to the user which is created using http://www.example.com/en/resetPaSS.php?id=$id&token=$token

  • 写回答

3条回答 默认 最新

  • doudang1890 2013-06-08 13:31
    关注

    If you use a form, then the id is not in the action url. You can also post the id by using a hidden input field

    You must use prepared statement to prevent sql injection:

    $sql = "UPDATE user SET password='?' WHERE id=?";
    $stmt = $link->prepare($sql);
    
    /* bind parameters */
    $stmt->bind_param("si", $pass_hash, $_GET['id']);
    
    /* execute query */
    $stmt->execute();
    

    EDIT By clicking the link you will be go to your page where a form is. You have to edit the the id to the form or action url to make your script working by doing the following steps

    make a variabele named id like this:

    $id = isset($_GET['id']) ? $_GET['id'] : $_POST['id'];
    

    also add hidden field to the form:

    <input type="hidden" name="id" value="<?php echo $id; ?>">
    

    Change the query bind_param to:

    $stmt->bind_param("si", $pass_hash, $id);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗