Welcome to WebmasterWorld Guest from 54.227.68.206

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

I can't get my change password PHP to work

     
5:14 am on Aug 29, 2010 (gmt 0)

New User

5+ Year Member

joined:Aug 29, 2010
posts:9
votes: 0


Every time I use this PHP script to change my password, all it does is change my password to nothing (blank). What is wrong with my PHP? Thank you very much for the help.

<?php
session_start();
if(!isset($_SESSION['username']) ||
(trim($_SESSION['username'])=='')) {
header("location: members_only_area.php");
exit();
}
?>

<?php

$dbhost = ""; //I erased these on purpose. These 4 things are correct
$dbname = "";
$dbuser = "";
$dbpass = "";

mysql_connect ($dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());

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

$result = mysql_query("SELECT password FROM members WHERE username='$username'");
if($password!=mysql_result($result, 0))
{
echo "The password you entered was incorrect.";
include "my_account.php";
}
if($newpassword==$confirmnewpassword)
$sql=mysql_query("UPDATE members SET password='$newpassword' where username='$username'");
if($sql)
{
echo "You have successfully changed your password.";
include "my_account.php";
}
else
{
echo "Your new password and new password confirmation values were different.";
include "my_account.php";
}
?>
7:57 pm on Aug 29, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Nov 28, 2004
posts:7999
votes: 0


Did you echo out post?

foreach ($_POST as $key => $value) {
echo "k: $key v: $value<br>";
}

The only thing that could be happening is it's not in post, if it's finding your username.