If, else if - php

Soldato
Joined
26 Nov 2005
Posts
3,839
Location
Doon the Bay (Newcastle)
Hi i'm slightly confused and wondered if someone could look at this code for me and sort it. Cheers.

if($count==1){
session_register("ADMIN");
session_register("ADMIN");
echo "<META HTTP-EQUIV='Refresh' CONTENT='0; URL=login_success1.php'>";
}

else if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword");
echo "<META HTTP-EQUIV='Refresh' CONTENT='0; URL=login_success.php'>";
//header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}



Basically i want to direct the admin account to somewhere else from normal login, basically everything now goes to the admin account so the second part isn't working although the else part is.

Thanks.
 
Hi mate, that almost worked, but now the admin entry doesn't go to admin, just normal log in.

Here's the whole code if that might help:

PHP:
<?php
session_start();
include("getinfo.php");


// Define $myusername and $mypassword
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];

$sql="SELECT * FROM Members WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
  session_register("ADMIN");
  session_register("ADMIN");
  echo "<META HTTP-EQUIV='Refresh' CONTENT='0; URL=login_success1.php'>";

  // Register $myusername, $mypassword and redirect to file "login_success.php"
  session_register("myusername");
  session_register("mypassword");
  echo "<META HTTP-EQUIV='Refresh' CONTENT='0; URL=login_success.php'>";
  //header("location:login_success.php");
}
else {
  echo "Wrong Username or Password";
}
?>
 
Sorted it in the end: Was a silly mistake really:

PHP:
<?php
session_start();
include("getinfo.php");


// Define $myusername and $mypassword
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];

$sql="SELECT * FROM Members WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
echo "$count" . "$myusername" . " " . "$mypassword";
if($count==1){
	if ($myusername == 'ADMIN' && $mypassword == 'ADMIN') {
  		session_register("myusername");
  		session_register("mypassword");
  		echo "<META HTTP-EQUIV='Refresh' CONTENT='0; URL=login_success1.php'>";
	} else {
		//echo "has gone past the success1";
  		// Register $myusername, $mypassword and redirect to file "login_success.php"
  		session_register("myusername");
  		session_register("mypassword");
		echo "<META HTTP-EQUIV='Refresh' CONTENT='0; URL=login_success.php'>";
  		header("location:login_success.php");
	}
} else {
  echo "Wrong Username or Password";
}
?>
 
Now i just need to amend values from a DB.

Can't even begin to think how i should be doing that. Ughhh...

Thanks for the help and advice, much appreciated.
 
Back
Top Bottom