I have the following code, which tries to see if someone selected a drop down menu item that is already part of the database. If it is, then the error message should show up.

$size_of_user_array = count($user_selects);
		$size_of_db_array = count($already_in_db);
		
		
		for($y=0;$y<$size_of_user_array;$y++)
		{
			$input = $user_selects[$y];
			for($r=0;$r<$size_of_db_array;$r++)
			{
				//echo "Already in $r = " .$already_in_db[$r];
				//echo "&nbsp;";
				//echo "user_selects[ $y ] = " . $user_selects[$y];
				$db_output = $already_in_db[$r];
				
				echo " $db_output = $input ";
				if($input == $db_output)
				{	
		    		echo "Table ". $already_in_db[$r] . " is already a part of database " . $_SESSION['category'] . "Please make your selections again";
					exit();
				}
			}
			if($input == "none")
			{
				// do something else
			}			
			else{
		    	$database_name = $_SESSION['category'] . "." . $input;
				//$sql=create_table($database_name);
				
		    	//echo "database name = " . $database_name;  // for debugging 
		    	//echo "Session abbr = " . $_SESSION['Abbr']; // ok ok, so perhaps I'm a little overkill with the debugging
		    	//echo "Input = " . $input; // but isn't it nice to just uncomment and see the stuff?
				
		    	//mysql_query($sql) or die("error making table!  Please contact system admin for more help." . mysql_error());
				//echo "Table Created!<br>";
		        //update_control($_SESSION['category'],$_SESSION['Abbr'],$input);
			}
		}			
	}
?>

The output for the code is as follows

array(5) { [0]=> string(8) "boxsets " [1]=> string(4) "none" [2]=> string(4) "none" [3]=> string(4) "none" [4]=> string(4) "none" } array(4) { [0]=> string(11) "accessories" [1]=> string(5) "track" [2]=> string(4) "sets" [3]=> string(7) "boxsets" } 
accessories = boxsets 
track = boxsets 
sets = boxsets
 boxsets = boxsets  <- should trigger
accessories = none 
track = none 
sets = none 
boxsets = none 
accessories = none 
track = none 
sets = none 
boxsets = none 
accessories = none 
track = none 
sets = none 
boxsets = none 
accessories = none t
rack = none 
sets = none 
boxsets = none

But it doesn't.

Can someone point out my mistake?

Thanks!

Kris

Tip: Somebody will probably reply to help you on this, but your chances of getting a reply are MUCH higher if you will narrow your problem down to the one or 2 steps where the problem actually occurs, then post only enough code to demonstrate the problem.

Many times, in this process, you'll discover the problem yourself. I know that many people like myself--when we see a long posting of code--give a quick read, then move on rather than analyze your 100 lines of code.

"Baby steps" is my motto in troubleshooting code or anything else. Use echo() statements liberally after each step to see if your variables contain what you think they should. Check every step of the way until you reach a step where something is not as you think it should be. Do not move to the next step until you resolve the problem. If you are unable--after searching the Internet, reading the documentation, etc--to fix your problem, post a simple code example to reproduce your problem, and state your question clearly. :)

all the comments in orange are debugging methods (echo()'s) which do what you suggest to make sure they are outputing the correct material.

I coded the entire page, and worked out all the kinks, then found I had a logic error, thus I had to interject in the middle of the page.

Thanks though, perhaps I'll cut down the code a little.

I think it's a syntaxitcal(sp) thing, a specific about php that I am missing...boy do I miss C++...:)

The line from your output:

boxsets = boxsets

Should be triggering the warning message as you say. So, what would make those two apparently identical strings NOT be equal? Spaces? Other white characters such as line endings, tabs, carriage returns? Try changing your debugging echo statement to this:

echo "|".$db_output."|=|".$input."|";

In your output, you should not have any space between the strings and the pipes. If you do, then walla, there is your problem. You can use trim() on both values to remove beginning and trailing white-space.

Cool! Thanks for the help, I'll try those out.

You were right.

The pipes show a trailing space on the side of the user selects.

I used a text file to upload those values, and after checking them, found a space after each entry.

:o Thanks for your help. I would have been stuck for quite some time without your assistance.

Kris

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.