简体   繁体   English

从 php 获取用户 id 以更改密码

[英]Take user id from php for change password

I have this code for change password on the personal page of the user on my website.我在我网站上用户的个人页面上有更改密码的代码。 The script working but the problem is that work's only on id "60".脚本工作,但问题是该工作仅适用于 ID“60”。 how I can take the id from the page and set in this code?我如何从页面中获取 id 并在此代码中设置? my page is like this "www.example.com/area-personale.php? id=60 ".我的网页是这样的“www.example.com/area-personale.php?ID = 60”。 and why the script start immediately when I enter on the page and i prefer that it starts when I press on submit.以及为什么当我进入页面时脚本立即启动,我更喜欢它在我按下提交时启动。

 </script> </head> <body> <form name="frmChange" method="post" action="" onSubmit="return validatePassword()"> <div style="width: 500px;"> <div class="message"><?php if(isset($message)) { echo $message; } ?></div> <table border="0" cellpadding="10" cellspacing="0" width="500" align="center" class="tblSaveForm"> <tr class="tableheader"> <td colspan="2">Change Password</td> </tr> <tr> <td width="40%"><label>Current Password</label></td> <td width="60%"><input type="password" name="currentPassword" class="txtField" /><span id="currentPassword" class="required"></span></td> </tr> <tr> <td><label>New Password</label></td> <td><input type="password" name="newPassword" class="txtField" /><span id="newPassword" class="required"></span></td> </tr> <td><label>Confirm Password</label></td> <td><input type="password" name="confirmPassword" class="txtField" /><span id="confirmPassword" class="required"></span></td> </tr> <tr> <td colspan="2"><input type="submit" name="submit" value="Submit" class="btnSubmit"></td> </tr> </table> </div> </form> </body> </html>
 <?php session_start(); $_SESSION["id_user"] = "60"; $conn = mysqli_connect("x", "x", "x", "x") or die("Connection Error: " . mysqli_error($conn)); ?> <?php if (count($_POST) > 0) { $result = mysqli_query($conn, "SELECT password FROM vm_users WHERE id_user='" . $_SESSION["id_user"] . "'"); $row = mysqli_fetch_array($result); if ($_POST["currentPassword"] == $row["password"]) { mysqli_query($conn, "UPDATE vm_users set password='" . $_POST["newPassword"] . "' WHERE id_user='" . $_SESSION["id_user"] . "'"); $message = "Password modificata"; } else $message = "Current Password is not correct"; } ?> <html> <head> <title>Change Password</title> <link rel="stylesheet" type="text/css" href="styles.css" /> <script> function validatePassword() { var currentPassword,newPassword,confirmPassword,output = true; currentPassword = document.frmChange.currentPassword; newPassword = document.frmChange.newPassword; confirmPassword = document.frmChange.confirmPassword; if(!currentPassword.value) { currentPassword.focus(); document.getElementById("currentPassword").innerHTML = "required"; output = false; } else if(!newPassword.value) { newPassword.focus(); document.getElementById("newPassword").innerHTML = "required"; output = false; } else if(!confirmPassword.value) { confirmPassword.focus(); document.getElementById("confirmPassword").innerHTML = "required"; output = false; } if(newPassword.value != confirmPassword.value) { newPassword.value=""; confirmPassword.value=""; newPassword.focus(); document.getElementById("confirmPassword").innerHTML = "not same"; output = false; } return output; }

I used this and now works!我用过这个,现在可以用了! $_SESSION["id_user"] = $_GET["id"] $_SESSION["id_user"] = $_GET["id"]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM