dongzhang5787 2016-03-31 23:03
浏览 29
已采纳

使用PHP中的$ _request变量进行数据库更新

I'm trying to update the user password in this code. I know it is not reliable since it does not has SQL injection prevention feature, I'm just trying to learn here. anyway, using $_request variable in my code does not work with the database query, it works when I want to display the variable with echo.

PHP code:

$newPassword=$_POST['newPassword'];
$confirmPassword=$_POST['confirmPassword'];
$userID1=$_REQUEST['ID'];
$code=$_GET['$code'];
echo "<h1>Hello " . $userID1 . "</h1>";
if (isset($_GET['submit'])) 
{

    if($newPassword == $confirmPassword ){

            mysql_query("UPDATE facultymember SET password='$newPassword' WHERE ID='$userID1'");
            $message = "Your password has been updated.";
           } 
    else 
        {
        $message = "New password does not equal Confirm password";
        }
 }

HTML form:

<form name="frmChange" action='newpass.php' method="GET" onSubmit="return validatePassword()">
    <div style="color:red;" "class="message"><?php if(isset($message)) { echo $message; } ?></div>
  Enter a new password
      <input type="text" name="newPassword">
    Re-enter the new password
      <input type="text" name="confirmPassword">

    <input name="submit" type="submit" value="Save Changes">
</form>
  • 写回答

1条回答 默认 最新

  • duanhao7786 2016-03-31 23:07
    关注

    wrong object to get value , when you are submitting GET request method="GET"

    $newPassword=$_POST['newPassword'];
    $confirmPassword=$_POST['confirmPassword'];
    or
    $newPassword=$_GET['newPassword'];
    $confirmPassword=$_GET['confirmPassword'];
    

    and no ID param also attached

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

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化