Jump to content


Photo

Change Username/password page


  • Please log in to reply
4 replies to this topic

#1 Deadmeat

Deadmeat
  • Members
  • PipPip
  • Member
  • 20 posts
  • Locationva

Posted 01 October 2003 - 11:04 PM

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.
Free Photoshop Tutorials[br]TutorialMan.com[br]---------------------------[br]Need Webspace thats cheap and reliable?[br]Quik-Online.org

#2 Blu_Smurf

Blu_Smurf
  • Members
  • PipPipPip
  • Advanced Member
  • 32 posts
  • LocationTexas

Posted 01 October 2003 - 11:57 PM

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">


#3 Deadmeat

Deadmeat
  • Members
  • PipPip
  • Member
  • 20 posts
  • Locationva

Posted 02 October 2003 - 12:28 AM

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.
Free Photoshop Tutorials[br]TutorialMan.com[br]---------------------------[br]Need Webspace thats cheap and reliable?[br]Quik-Online.org

#4 Blu_Smurf

Blu_Smurf
  • Members
  • PipPipPip
  • Advanced Member
  • 32 posts
  • LocationTexas

Posted 02 October 2003 - 01:53 AM

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.

#5 Deadmeat

Deadmeat
  • Members
  • PipPip
  • Member
  • 20 posts
  • Locationva

Posted 02 October 2003 - 10:09 PM

Ahh, thanks. That helped a bunch.
Free Photoshop Tutorials[br]TutorialMan.com[br]---------------------------[br]Need Webspace thats cheap and reliable?[br]Quik-Online.org




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users