else before if (i ment !)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
reecec
Forum Contributor
Posts: 218
Joined: Sun Apr 02, 2006 7:12 am

else before if (i ment !)

Post 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
Last edited by reecec on Sat Jan 27, 2007 11:02 am, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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?
reecec
Forum Contributor
Posts: 218
Joined: Sun Apr 02, 2006 7:12 am

hi

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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";
}
mmcoolkid94
Forum Newbie
Posts: 8
Joined: Mon Jun 19, 2006 9:07 pm

Post by mmcoolkid94 »

In php code you must put if before else.

reecec
Forum Contributor
Posts: 218
Joined: Sun Apr 02, 2006 7:12 am

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Do we need to pull up a thread coming up on a year old?
reecec
Forum Contributor
Posts: 218
Joined: Sun Apr 02, 2006 7:12 am

Post by reecec »

no but it just to put it straight lol
Post Reply