473,387 Members | 1,592 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Update Password Checker

38
Hi folks,

Can anyone spot any problems with this? It's not returning any errors.

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?php 
  3. // login2.php
  4. include("connect_courses.php");
  5.  
  6. if(isset($_POST['Submit']) && $_POST['Submit'] == "Submit")
  7. {
  8.  
  9. $myusername = $_POST['myusername'];
  10. $mypassword = $_POST['mypassword'];
  11. $mynewpassword = $_POST['mynewpassword'];
  12. $confirmnewpassword = $_POST['confirmnewpassword'];
  13.  
  14. $result = mysql_query("SELECT password FROM users WHERE username='$myusername'");
  15. if(!$result) 
  16. echo "The username you entered does not exist. <a href=index.php>Try Again</a>"; 
  17. else 
  18. if($password!= mysql_result($result, 0)) 
  19. echo "You entered an incorrect password. <a href=index.php>Try Again</a>"; 
  20. else
  21. if($mynewpassword==$confirmnewpassword) 
  22.     $sql=mysql_query("UPDATE users SET password='$mynewpassword' where username='$myusername'"); 
  23.     if($sql) 
  24.     { 
  25.     echo "Congratulations! You have successfully changed your password."; 
  26.     }
  27. else
  28. echo "The new password and confirm new password fields must be the same. <a href=change_password_courses.php>Try Again</a>"; 
  29. }  }  
  30. ?>
  31.  
  32.  
Many thanks.
Aug 16 '09 #1
7 2543
Dormilich
8,658 Expert Mod 8TB
why should it return any errors?
Aug 16 '09 #2
Philth
38
By that I mean it's not echoing any of the messages.
Aug 16 '09 #3
The if-statement on line 25 is missing curly braces, the scope you seem to intend to have based on your indentation is not the way php will see it. As it is written, the only way you will have no output is if the first if statement evaluates to false, I would put an else for that statement to see if that is the case. A couple of other problems I see is you are not safeguarding again a mysql injection attack (run all user input through mysql_real_escape_string()), and you aren't doing any error checking on the query execution, so if there is an error with the sql, you won't know about it. Try this:
Expand|Select|Wrap|Line Numbers
  1. $sql=mysql_query("...") or die($qry."\n".mysql_error());
Aug 16 '09 #4
pezhvak
17
this line is wrong:
Expand|Select|Wrap|Line Numbers
  1. if(isset($_POST['Submit']) && $_POST['Submit'] == "Submit")
change it to:
Expand|Select|Wrap|Line Numbers
  1. if(isset($_POST['Submit']))
  2.      if($_POST['Submit'] == "Submit")
why i do this::
in the first IF we check if "Submit" is set or not and in the second IF we check if value of "Submit" field are equal with "Submit" string or not

in the way you wrote if the "Submit" field isn't set the PHP will trigger an error about your second statement in your IF condition::
Expand|Select|Wrap|Line Numbers
  1. if(isset($_POST['Submit']) && $_POST['Submit'] == "Submit")
its why $_POST['submit'] is not set but you want to check if the value are equal with "Submit" or not...

i don't think this is the problem of your script, but i don't have enough time to read all of your script right now.. i will check it later,
Aug 20 '09 #5
Dormilich
8,658 Expert Mod 8TB
@pezhvak
not quite, if isset() returns false the second expression is not executed because the condition can never become true.
Aug 20 '09 #6
Markus
6,050 Expert 4TB
@Dormilich
Exactly. If one condition fails, the subsequent conditions are skipped (unless you are negating the condition).
Aug 20 '09 #7
pezhvak
17
ok... ok someone said that before..
Aug 20 '09 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Richard M | last post by:
Can anyone please lend me a hand, I'm trying to design a cookie based password system. I have managed to do everything bar one thing that is driving me crazy. I have a MYSQL database called...
1
by: magda muskala | last post by:
hi, I have a little problem with the following part of my code. I use post method to get the password from the form . Because there is an encrypted password in mysql database, I check with $pass...
3
by: Fredrik/Sweden | last post by:
Hi folks ! got this problem... i have a table 'Accounts' in my database, which contains a bunch of users. From the main menu i choose "edit user" and all users in the db are presented in a table....
13
by: J.P | last post by:
Hi! Anyone knows if it's possible to do an update if, and only if my condition is TRUE. Example: In MYTABLE I have three columns, like this: ID(INT), PUBLISH(ENUM(Y,N)),...
7
by: andri.wardhana | last post by:
Hi Guys, I have a problem with my ASP file. since I'm all new in ASP, i found that the error statement generated by ASP is confusing. basically what I want to do in this script is ability to...
3
by: chrisspen | last post by:
Is there a way to loop through all instantiated objects and update their classes when a source file changes? I know about Michael Hudson's method...
13
by: kolmogolov | last post by:
/* Hi, I have removed things irrelevant to reproducing the problem. What's wrong with my code? Thanks in advance for any hint! 1166425362 */ #include <stdio.h> #include <stdlib.h> #include...
3
by: dhaneshrs | last post by:
I have a gridview i managed to update using the edit option in the smartmenu. The problem comes when i delete a value or make a value read only. Say i have a table Employee with the following...
5
by: =?Utf-8?B?UlBhcmtlcg==?= | last post by:
I used the wizard to generate a typed dataset for my table and let it create my SPROCs. It created everything, and the GetData() method and the custom GetByUserName query works great, but when I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.