Page 1 of 1

else before if (i ment !)

Posted: Wed Jun 21, 2006 11:48 am
by reecec
hi

is there a way of doing the else before the if i think i have seen something like it before.

if not how do i know what else is going with what if as i want the if to carry on but all the elses to come at the end


thanks reece


hope someone can help

Posted: Wed Jun 21, 2006 12:00 pm
by feyd
the else will not run before the if.

As for the rest of your post... huh? Can you explain some more or post some code that may illustrate it?

hi

Posted: Wed Jun 21, 2006 12:06 pm
by reecec

Code: Select all

<?
if ($new==$new1) {
// search database to check for user
$request = "SELECT * FROM registered_members WHERE username='$cookie'";

// hand over the request
$results = mysql_query($request);
$rows = mysql_query($results);
$oldpasswordstored = $rows['password'];

$flag="OK";   // This is the flag and we set it to OK
$msg="";        // Initializing the message to hold the error messages

if(strlen($new) < 4){    // checking the length of the entered userid and it must be more than 5 character in length
$msg=$msg."( Please enter password more than 5 character length  )<BR>";
$flag="NOTOK";   //setting the flag to error flag.
}

if($flag <>"OK"){
echo "<center>$msg <br> <input type='button' value='Retry' onClick='history.go(-1)'></center>";
}
else
{ // all entries are correct and let us proceed with the database checking etc …


// strip away any dangerous tags
$user=strip_tags($user);
$old=strip_tags($old);


// remove spaces from variables
$user=str_replace(" ","",$user);
$old=str_replace(" ","",$old);


// remove escaped spaces
$user=str_replace("%20","",$user);
$old=str_replace("%20","",$old);

// add slashes to stop hacking
$user=addslashes($user);
$old=addslashes($old);

// hash users password for security (32 chars random - md5)
$pass=md5($pass);
$old=md5($old);

if ($oldpasswordstored==$old) {

// Insert data into database
$sql="UPDATE registered_members(password=$pass)";
$result=mysql_query($sql);
}}
else 
{
echo "The 2 Passwords you entered did not match please retry or this is not your old password";
}


?>


i want an else for the $new==$new1

and an else for the $oldpasswordstored==$old

but the if the if is correct i want it to carry on



i think im thinking of this to hard and just cant see where to add it

thanks for you reply

Posted: Wed Jun 21, 2006 12:13 pm
by feyd
The following is indented and has a few added bits that mark the ends of each if and I tried to add the brace needed for your last else.

I seriously suggest using an editor that has, at minimum, brace/bracket/paren matching.

Code: Select all

if ($new==$new1)
{
	// search database to check for user
	$request = "SELECT * FROM registered_members WHERE username='$cookie'";

	// hand over the request
	$results = mysql_query($request);
	$rows = mysql_query($results);
	$oldpasswordstored = $rows['password'];

	$flag="OK";   // This is the flag and we set it to OK
	$msg="";        // Initializing the message to hold the error messages

	if(strlen($new) < 4)
	{    // checking the length of the entered userid and it must be more than 5 character in length
		$msg=$msg."( Please enter password more than 5 character length  )<BR>";
		$flag="NOTOK";   //setting the flag to error flag.
	} // if(strlen($new) < 4)

	if($flag <> "OK")
	{
		echo "<center>$msg <br> <input type='button' value='Retry' onClick='history.go(-1)'></center>";
	} // if($flag <> "OK")
	else
	{ // all entries are correct and let us proceed with the database checking etc …


		// strip away any dangerous tags
		$user=strip_tags($user);
		$old=strip_tags($old);


		// remove spaces from variables
		$user=str_replace(" ","",$user);
		$old=str_replace(" ","",$old);


		// remove escaped spaces
		$user=str_replace("%20","",$user);
		$old=str_replace("%20","",$old);

		// add slashes to stop hacking
		$user=addslashes($user);
		$old=addslashes($old);

		// hash users password for security (32 chars random - md5)
		$pass=md5($pass);
		$old=md5($old);

		if ($oldpasswordstored==$old)
		{
			// Insert data into database
			$sql="UPDATE registered_members(password=$pass)";
			$result=mysql_query($sql);
		} // if ($oldpasswordstored==$old)
	}
} // if ($new==$new1)
else
{
	echo "The 2 Passwords you entered did not match please retry or this is not your old password";
}

Posted: Wed Jun 21, 2006 7:56 pm
by mmcoolkid94
In php code you must put if before else.


Posted: Sat Jan 27, 2007 11:01 am
by reecec
i obviously dint know much about php whe i posted this

just remembered that i asked this

this is what i mean

if (!$check)
{
}


like that,

i dint explain it every well before

thanks

Posted: Sat Jan 27, 2007 2:55 pm
by feyd
Do we need to pull up a thread coming up on a year old?

Posted: Sun Jan 28, 2007 5:39 am
by reecec
no but it just to put it straight lol