if else statement gets ignored?

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
FluxNYC
Forum Newbie
Posts: 6
Joined: Sun Mar 25, 2007 6:43 pm

if else statement gets ignored?

Post by FluxNYC »

Hey so basically im making a script to re-order a list the catch is there are multiple lists in this case banner and item. To determine what list is later hit it checks for the type. Now when i pass the variable banner for TYPE and do the echos the first echo that comes out is "side_banners" but then once it gets to the second echo the table is suddenly "items". Any ideas?

Code: Select all

$type_new = $_REQUEST[type];
		if($type_new=="banner")
		{
			$table = $banners_table;
			$column = "side_banner_id";
			echo "banner sayas this is $table  ..";

		}
		elseif($type_new=="item");
		{
			$table = $items_table;
			$column = "item_id";
		}	
		
	if($_REQUEST[move] == "up")
	{
		echo "After the table is $table"; 

}
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

:? still using _REQUEST[type] instead of _REQUEST['type'], probably means you're not using error_reporting=E_ALL either.

try

Code: Select all

error_reporting(E_ALL);
ini_set('display_errors', true);

switch($_REQUEST['type']) {
  case 'banner':
    $table = $banners_table;
    $column = "side_banner_id";
    echo "banner sayas this is $table  ..";
    break;
  case 'item':
    $table = $items_table;
    $column = "item_id";
    echo "banner sayas this is $table  ..";
    break;
  default:
    echo "unknown _REQUEST[type]: ", $_REQUEST['type'];
    break;
}
feedback would be nice.
FluxNYC
Forum Newbie
Posts: 6
Joined: Sun Mar 25, 2007 6:43 pm

Post by FluxNYC »

Hey. Using a case solved it but there no errors after ptuting in the appropriate 's. still find it weird an ifelse statement didnt work...thanks though :-)
Elias
Forum Newbie
Posts: 2
Joined: Tue Mar 27, 2007 8:54 pm

Post by Elias »

Code: Select all

$type_new = $_REQUEST[type]; 
                if($type_new=="banner") 
                { 
                        $table = $banners_table; 
                        $column = "side_banner_id"; 
                        echo "banner sayas this is $table  .."; 

                } 
                elseif($type_new=="item"); 
                { 
                        $table = $items_table; 
                        $column = "item_id"; 
                }        
                
        if($_REQUEST[move] == "up") 
        { 
                echo "After the table is $table"; 

}
Could of also done it like this:

Code: Select all

$type_new = $_REQUEST[type]; 
                if($type_new=="banner") 
                { 
                        $table = $banners_table; 
                        $column = "side_banner_id"; 
                        echo "banner sayas this is $table  .."; 

                } 
                elseif($type_new=="item"); 
                { 
                        $table = $items_table; 
                        $column = "item_id"; 
                }        
                
        if($_REQUEST[move] == "up") 
        { 
                echo "After the table is $table"; 

} else {

code:
Please correct me if i am wrong. I am still learning :D
Begby
Forum Regular
Posts: 575
Joined: Wed Dec 13, 2006 10:28 am

Post by Begby »

FluxNYC wrote:Hey. Using a case solved it but there no errors after ptuting in the appropriate 's. still find it weird an ifelse statement didnt work...thanks though :-)
As Volka has pointed out to you in multiple posts

- Start quoting things right
- Turn on error reporting following his examples
- Start using mysql_error as per his examples

These things will help make it more obvious what the problem is when things fail.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Just a follow up to the advice you are getting on error reporting and error checking...

Only do this on your local development environment. DO NOT LEAVE DISPLAY ERRORS ON IN PRODUCTION. Now that this is clarified, you can carry on ;)
Post Reply