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 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题