Page 1 of 1

code showing message

Posted: Sun Feb 26, 2012 2:59 am
by fullyloaded
hi
i was wondering if anyone had any idea how to fix the error in my code? the problem im having is this message is showing before i do anything on my page (Old password incorrect. please try again.) but other then that the code is work thanks...

Code: Select all

<?PHP
$reqlevel = 1;
include("membersonly.inc.php");
if ($allowChangePassword == false){die($disabledFeatures);}
$oldpass1 = hash('sha512', $_POST['oldpass']);
$password1 = hash('sha512', $_POST['password']);
$password2 = hash('sha512', $_POST['password2']);
if ($password1 == $password2 && $password1 <> ""){
$query = "Select * from ".$DBprefix."signup where username='$user_currently_loged' And password='$oldpass1'";
$result = mysql_query($query); 
if ($row = mysql_fetch_array($result)){ 
$query = "UPDATE ".$DBprefix."signup Set password = '$password1' where username='$user_currently_loged'";  
$result = mysql_query($query); 
$_SESSION["pass"] = $password1;
makeform("You password was changed.");
}else{
makeform("Old password incorrect. please try again.");
}
}else{
if ($password1 == ""){makeform("");}
else{makeform("Your password do not match try again.");}
}
function makeform($errormessage){
?>

Code: Select all

<?PHP echo "<font color=\"#FF0000\"><strong>$errormessage</strong></font>";?>

Re: code showing message

Posted: Sun Feb 26, 2012 7:11 am
by Celauran
You aren't checking if the form has been submitted, you're jumping right to this:

Code: Select all

if ($password1 == $password2 && $password1 <> "")

Re: code showing message

Posted: Mon Feb 27, 2012 3:20 pm
by fullyloaded
hi
thanks for the reply how would i go about fixing this i tried a lot of things with no luck i still have a lot to learn in php thanks...

Re: code showing message

Posted: Mon Feb 27, 2012 3:23 pm
by social_experiment
a common method of checking for a submitted form is this

Code: Select all

<?php
 if (isset($_POST['submitButtonName'])) {
   // process form
 }
?>