Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Switch & Case problem
Old 04-01-2005, 04:18 PM Switch & Case problem
Novice Talker

Posts: 13
Trades: 0
Hello again,

I have 4 groups that access my webapp and they are listed within the cases in the code below. I keep recieving a parse error I can not for the life of me get around. The line that gives me the parse error is the bottom else { after all of the cases and right before the header info. Heres the code

PHP Code:
<?php
require 'globals/dbconnect.php';

session_start();
     
$process_login "SELECT * FROM users WHERE user_name='$user_name' AND password='$password'";
$login_result mysql_query($process_login) or die (mysql_error());  
if(
mysql_num_rows($login_result) > 0){
$result mysql_fetch_array($login_result);
$groups $result['groups'];
switch(
$groups) { 
case 
"cbragent":
$_SESSION['groups'] = $groups;
$_SESSION['logged_in'] = TRUE;
$_SESSION['user_name'] = $user_name;
header("location: cbragent.php");
break;
case 
"cbrclient":
$_SESSION['groups'] = $groups;
$_SESSION['logged_in'] = TRUE;
$_SESSION['user_name'] = $user_name;
header("location: cbrclient.php");
break;
case 
"cpmagent":
$_SESSION['groups'] = $groups;
$_SESSION['logged_in'] = TRUE;
$_SESSION['user_name'] = $user_name;
header("location: cpmagent.php");
break;
case 
"cpmclient":
$_SESSION['groups'] = $groups;
$_SESSION['logged_in'] = TRUE;
$_SESSION['user_name'] = $user_name;
header("location: cpmclient.php");
break;
};  
else { 
// <--------THIS IS WHERE I HAVE THE PROBLEM :mad: 
header("location: login.php?error=1");
exit;
};
?>
Suggestions?
aesop is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-01-2005, 05:05 PM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
Remove the ; after the } on the line just above it.
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 04-01-2005, 05:09 PM
Novice Talker

Posts: 13
Trades: 0
did that.. no dice

however i discovered that you cant use else statements in this kind of environment. And I forgot to add in a default for the case area. SO after dropping the else statement and assigning a default, I still cant get it to work

PHP Code:
<?php
require 'globals/dbconnect.php';

session_start();
     
$process_login "SELECT * FROM users WHERE user_name='$user_name' AND password='$password'";
$login_result mysql_query($process_login) or die (mysql_error());  
if(
mysql_num_rows($login_result) > 0){
$result mysql_fetch_array($login_result);
$groups $result['groups'];
switch(
$groups) { 
case 
"cbragent":
default: 
"location: login.php?error=1";
$_SESSION['groups'] = $groups;
$_SESSION['logged_in'] = TRUE;
$_SESSION['user_name'] = $user_name;
header("location: cbragent.php");
break;
case 
"cbrclient":
default: 
"location: login.php?error=1";
$_SESSION['groups'] = $groups;
$_SESSION['logged_in'] = TRUE;
$_SESSION['user_name'] = $user_name;
header("location: cbrclient.php");
break;
case 
"cpmagent":
default: 
"location: login.php?error=1";
$_SESSION['groups'] = $groups;
$_SESSION['logged_in'] = TRUE;
$_SESSION['user_name'] = $user_name;
header("location: cpmagent.php");
break;
case 
"cpmclient":
default: 
"location: login.php?error=1";
$_SESSION['groups'] = $groups;
$_SESSION['logged_in'] = TRUE;
$_SESSION['user_name'] = $user_name;
header("location: cpmclient.php");
break;

?>
aesop is offline
Reply With Quote
View Public Profile
 
Old 04-01-2005, 05:22 PM
Novice Talker

Posts: 13
Trades: 0
disregard, got it figured out. But my next issue is to get it so I know that I am only looking at my info only. This just puts me on a page thats not going to contain my data.

PHP Code:
<?php
require 'globals/dbconnect.php';

session_start();
     
$process_login "SELECT * FROM users WHERE user_name='$user_name' AND password='$password'";
$login_result mysql_query($process_login) or die (mysql_error());  
if(
mysql_num_rows($login_result) > 0){
$result mysql_fetch_array($login_result);
$groups $result['groups'];
switch(
$groups) { 
case 
"cbragent":
default: (
"login.php?error=1");
$_SESSION['groups'] = $groups;
$_SESSION['logged_in'] = TRUE;
$_SESSION['user_name'] = $user_name;
header("location: cbragent.php");
break;
case 
"cbrclient":
default: (
"login.php?error=1");
$_SESSION['groups'] = $groups;
$_SESSION['logged_in'] = TRUE;
$_SESSION['user_name'] = $user_name;
header("location: cbrclient.php");
break;
case 
"cpmagent":
default: (
"login.php?error=1");
$_SESSION['groups'] = $groups;
$_SESSION['logged_in'] = TRUE;
$_SESSION['user_name'] = $user_name;
header("location: cpmagent.php");
break;
case 
"cpmclient":
default: (
"login.php?error=1");
$_SESSION['groups'] = $groups;
$_SESSION['logged_in'] = TRUE;
$_SESSION['user_name'] = $user_name;
header("location: cpmclient.php");
break;}
}; 
?>
aesop is offline
Reply With Quote
View Public Profile
 
Old 04-01-2005, 05:53 PM
Kyrnt's Avatar
The Post-Mod Years

Posts: 2,536
Location: Western Maryland
Trades: 0
You can only have one default for a switch statement and it does not take a value. The default clause is meant as a catch all for all other values not covered by other cases. See simple example below.

Your code has multiple defaults and pass values to it; that is your problem.

PHP Code:
<?php

$n 
2;
$value "";

switch( 
$n )
{

    case 
1:  $value "one";
                 break;
    case 
2:  $value "two";
                 break;
    default:  
$value "A really big number.";
                 break;


}
?>
__________________
—Kyrnt
Kyrnt is offline
Reply With Quote
View Public Profile Visit Kyrnt's homepage!
 
Old 04-01-2005, 05:56 PM
Novice Talker

Posts: 13
Trades: 0
ok. so how do i assign each case to get to their own page that is in their respective headers?
aesop is offline
Reply With Quote
View Public Profile
 
Old 04-02-2005, 11:46 AM
Kyrnt's Avatar
The Post-Mod Years

Posts: 2,536
Location: Western Maryland
Trades: 0
Try removing the default clauses from your switch statement and replace them with one line at the end of your switch statement:

PHP Code:
default:  header("location: login.php?error=1"); 
__________________
—Kyrnt
Kyrnt is offline
Reply With Quote
View Public Profile Visit Kyrnt's homepage!
 
Reply     « Reply to Switch & Case problem
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.25308 seconds with 12 queries