Jump to content

Change Username/password page


Deadmeat

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.

Link to comment
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.

Link to comment
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.

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.