更改mysql表中的密码? [英] change password in mysql table?

查看:150
本文介绍了更改mysql表中的密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好我的更改密码脚本有问题。即时通讯设法允许用户更改他们的密码在MySQL表'ptb_users.password'它假设将此存储为md5。

Hi im having a problem with my change password script. im trying to allow a user to change their password in the mysql table 'ptb_users.password' it's suppose to store this as md5.

当我在我的表单提交时,我假设它转到changepassword.php,但页面只是空白,没有任何回应,我没有得到任何错误。

When i hit submit in my form, i'm assuming it goes to changepassword.php but the page is just blank, nothing is echoed and im not getting any errors.

有人可以告诉我我去哪里错了,谢谢

Can someone please show me where im going wrong with this, thanks

这是我的表格:

<?php 
// CONNECT TO THE DATABASE
    require('includes/_config/connection.php');
// LOAD FUNCTIONS
    require('includes/functions.php');
// GET IP ADDRESS
    $ip_address = $_SERVER['REMOTE_ADDR'];  
?>

  <?php require_once("includes/sessionframe.php"); 
  require('includes/checks.php');
?>


<?php

if (isset ($_GET['to'])) {
$user_to_id = $_GET['to'];

}

?> 

<?php 
//We check if the form has been sent
if(isset($_POST['subject'], $_POST['message_content']))
{
    $subject = $_POST['subject'];
    $content = $_POST['message_content'];
        //We remove slashes depending on the configuration
        if(get_magic_quotes_gpc())
        {
                $subject = stripslashes($subject);
                $content = stripslashes($content);
        }
        //We check if all the fields are filled
        if($_POST['subject']!='' and $_POST['message_content']!='')
        {
            $sql = "INSERT INTO ptb_messages (id, from_user_id, to_user_id, subject, content) VALUES (NULL, '".$_SESSION['user_id']."', '".$user_to_id."', '".$subject."', '".$content."');";
            mysql_query($sql, $connection);

            echo "<div class=\"infobox2\">The message has successfully been sent.</div>";
        }
}


if(!isset($_POST['subject'], $_POST['message_content']))

if (empty($_POST['subject'])){
        $errors[] = 'The subject cannot be empty.';

    if (empty($_POST['body'])){
        $errors[] = 'The body cannot be empty.';

    }
    }

{
?>


<form method="post" action="includes/changepassword.php" name="form1" id="form1">
<input type="password" name="oldpassword" id="password" class="subject" placeholder="Old Password">

<input type="password" name="oldpassword" id="password" class="message" placeholder="Old Password">

<input type="password" name="newpassword" id="newpassword" class="message" placeholder="New Password">

<input type="image" src="assets/img/icons/loginarrow1.png" name="submit" id="submit" class="submit">
</form>

这是我的mysql函数:

And here's my mysql function:

<?php
require_once("session.php"); 
require_once("functions.php");
require('_config/connection.php');
?>
<?php 

session_start();

include '_config/connection.php'; 

$password = $_POST['password'];
$newpassword = $_POST['newpassword'];
$confirmnewpassword = $_POST['confirmnewpassword'];

$result = mysql_query("SELECT password FROM ptb_users WHERE id=".$_SESSION['user_id']."");





if(!$result) 
{ 
echo "The username you entered does not exist"; 
} 
else 
if($password!= mysql_result($result, 0)) 
{ 
echo ""; 
} 
if($newpassword=$confirmnewpassword) 
{
    $newpassword=md5($newpassword);
    $sql=mysql_query("UPDATE ptb_users SET password='$newpassword' WHERE id=".$_SESSION['user_id'].""); 
}
    if($sql) 
    { 
    echo "Thank You. Your Password has been successfully changed."; 
    }
else
{ 
echo "The new password and confirm new password fields must be the same"; 
}  
?>


推荐答案

if(isset($_POST['submit']))
{

   $email = $_POST['email'];
   echo $newpassword = ($_POST['password1']);
   echo $confirmpasssword = ($_POST['password2']);

        if($newpassword=$confirmpassword) 
        {
            echo $newpassword = md5($newpassword);
            echo $result = mysql_query("UPDATE users SET password='$newpassword' WHERE email='$email' "); 
        }
                if($result) 
                { 
                echo "Thank You. Your Password has been successfully changed."; 
                }
            else
            { 
            echo "The new password and confirm password fields must be the same"; 
            }  
}

can anyone tell me is this correct coding, to change password and store in mysqldb. 

这篇关于更改mysql表中的密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆