Jump to content

Archived

This topic is now archived and is closed to further replies.

Deadmeat

Change Username/password page

Recommended Posts

I have been stuck trying to fix my \"profile.php\" page for hours. I\'ve tried so many things, all with no luck. What I have is a login page. From there, users can change their passwords to whatever they\'d like. The script works just fine, except when they enter no data. I would like it to revert to the old password (ie. no changes occur to the database upon submitting) if they do not wish to make a change. Another option of this feature is allowing them to change one field (username only, not password), but without giving the field they leave blank a null value.

 

My Code:

if(!isset($_SESSION[\'username\'])){ 

    echo "You must be logged in to change your profile.";

    include \'login_form.html\';

    exit(); 

}



$username = $_POST[\'username\'];

$password = $_POST[\'password\'];

$check_password = $_POST[\'check_password\'];

$id = $_SESSION[\'id\'];



if($password != $check_password){

echo "Your passwords do not match. Please enter them again.";

include \'profile.html\';

exit();

}



if((!isset($username)) || (!isset($password)) || (!isset($check_password))){ 

   if(!isset($username)){

$username = $_SESSION[\'username\'];

   }

   if(!isset($password) && !isset($check_password)){

$password = $_SESSION[\'password\'];

   }

}



$password = md5($password);



mysql_query("UPDATE users SET username=\'$username\' WHERE id=\'$id\'");

mysql_query("UPDATE users SET password=\'$password\' WHERE id=\'$id\'");

 

If I cannot get this to work, I suppose I could 1) fill in the current username for them, and 2)require a minimum password length (I should have anyway).

 

I\'de rather try my first idea out though, so if you could, please help. Thanks so much.

Share this post


Link to post
Share on other sites

ok, on your text fields, just do this and it will ahve input in them...

 

<input type="password" value="$password" name="password">

<input type="text" value="$username" name="username">

Share this post


Link to post
Share on other sites

I don\'t understand.. I have input, my problem is that when I do not enter data, it will send NULL to the database.

 

If it has something to do with \"value=$password\" then it will not work for me because my input page is an html file, separate from the php code.

Share this post


Link to post
Share on other sites

oh, then.... something like htis

 

[php:1:a66e04f4f4]<?php

if(!$_POST[\'username\']) {

$sql = mysql_query(\"UPDATE TABLE SET password = \'$password\' WHERE uname = \'$uname\'\");

 

} elseif (!$_POST[\'password\']) {

$sql = mysql_query(\"UPDATE TABLE SET uname = \'$uname\' WHERE uname = \'$uname\'\");

 

} else {

$sql = mysql_query(\"UPDATE TABLE SET uname = \'$uname\' WHERE uname = \'$uname\'\");

$sql = mysql_query(\"UPDATE TABLE SET password = \'$password\' WHERE uname = \'$uname\'\");

 

 

?>[/php:1:a66e04f4f4]

 

Think this is what you mean. Checks to see if username is blank, if so, it only updates password. If password is blank, updates username. Else, updates both.

Share this post


Link to post
Share on other sites

×

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.