Jump to content

whats wrong?? (change password form)


techiefreak05

Recommended Posts

[code]<?php
include("database.php");

$md5pass1 = md5($_POST['newpass']);
$username = $_SESSION['username'];

if(isset($_POST['sublogin'])){
mysql_select_db('zyco_zycologin')
or die('Error, cannot select mysql database');

$query = "UPDATE password SET password = PASSWORD($md5pass1)". "WHERE username = $username";

mysql_query($query) or die(error! password was NOT updated!);
}
?>

<form action="" method="post">
<table align="center" border="0" cellspacing="0" cellpadding="3" BGCOLOR=56A5EC>
<tr><td >Username:</td><td><input type="text" name="newpass" maxlength="30"></td></tr>
<tr><td colspan="2" align="right"><input type="submit" name="sublogin" value="Update Password"></td></tr>

[/code]

id there anything obviously wrong with this?? there is somethnig wrong with the "mysql_query($query) or die(error! password was NOT updated!);"
Link to comment
Share on other sites

I just did this as a test

[code=php:0]<?php
include("db.php");
$username = "test";
$pass = "test1234";
$password = md5($pass);
$sql ="UPDATE users SET password = '$password' WHERE username = '$username'";
$result = mysql_query($sql) or die(mysql_error());
if (!$result) {
    echo "There was an error";
}else{
    echo "password was reset to $pass";
}
?>[/code]

It worked just fine.
Link to comment
Share on other sites

You should realy have two fields, one for the password and another to confirm the new password. 

Here is a code that I tested. So I know that it works.

[code=php:0]<?php
if (isset($submit)) {
    if ((!$password) || (!$confirm)) {
        echo "You must enter both fields";
        exit;
    }
    if ($password !== $confirm) {
        echo "Your passwords do not match";
        exit;
    }
    include("db.php");
    $username = $_SESSION['username'];
    $mdpwd = md5($password);
    $sql ="UPDATE users SET password = '$mdpwd' WHERE username = '$username'";
    $result = mysql_query($sql) or die(mysql_error());
     if (!$result) {
         echo "There was an error";
    }else{
         echo "password was reset to $password";
    }
}
?>
//put your html below here
[/code]

Hope this helps,
Tom
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.