Deadmeat Posted October 1, 2003 Share Posted October 1, 2003 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. Quote Link to comment Share on other sites More sharing options...
Blu_Smurf Posted October 1, 2003 Share Posted October 1, 2003 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"> Quote Link to comment Share on other sites More sharing options...
Deadmeat Posted October 2, 2003 Author Share Posted October 2, 2003 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. Quote Link to comment Share on other sites More sharing options...
Blu_Smurf Posted October 2, 2003 Share Posted October 2, 2003 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. Quote Link to comment Share on other sites More sharing options...
Deadmeat Posted October 2, 2003 Author Share Posted October 2, 2003 Ahh, thanks. That helped a bunch. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.