PHP execution order weirdness

If run as shown below, the result of if($ops==“” && $opother==“”) is ALWAYS true, even when $ops<>“”
If you print $ops and exit before the if() concerned (shown below at // *** the offending item *** //), it contains a value.
Placing an exit anywhere else in the script below the if() results (correctly) in a false result.

I think there’s something strange going on with execution order - any ideas much appreciated. Full code below.
The form enctype is multipart/form-data in case that’s significant?




foreach($_POST as $k=>$v) {
		if(!is_array($v)) {	
		if (strpos($k,"*") && $v=="") {$k=str_replace("*","",$k);	$_SESSION["missing"]["profile"][$k]=1;}
		if(strpos($k,"x_")===false) {
	if($k=="user"){err("System field found in submission","A fieldname was found in the information sent by your browser which should not be there.");}


foreach($_POST as $k=>$v) {
		if (is_array($v)) {
			foreach($v as $kk=>$vv) {
				if($prefix=="op") {$ops.="($user,'$sessionid',$vv),";}
				if($prefix=="bb") {$bbs.="($user,'$sessionid',$vv),";}

//*** the offending item ***//
if($ops=="" && $opother=="") {
	$_SESSION["errors"]["profile"]["ops"]="Please choose at least one category or enter new ones below";

//if everything passes muster...
if($_SESSION["missing"]["profile"]=="" && $_SESSION["errors"]["profile"]=="") {

mysql_query("UPDATE user SET $sqlstring WHERE user=$user");			
// upload logo
if ($_FILES["x_newlogo"]) {$ext=substr($_FILES['x_newlogo']['name'],strpos($_FILES['x_newlogo']['name'],"."));
if ($ext && !in_array(strtolower($ext),array(".bmp",".jpg",".jpeg",".png",".gif"))) {$err="The file type you uploaded is not allowed. Please upload a BMP, GIF, JPG or PNG file.<br/>The filename must be in the format <i>filename.ext</i>";}}
if ($_FILES['x_newlogo']) {	
		// extension already set in validation, above
		if (move_uploaded_file($_FILES['x_newlogo']['tmp_name'], "adimg/$filename")){
			mysql_query("UPDATE user SET newlogo='$filename' WHERE user=$user");

mysql_query("DELETE FROM user_op WHERE user=$user");
mysql_query("DELETE FROM user_bb WHERE user=$user");

	if($ops) {
		mysql_query("INSERT	INTO user_op(user,sessionid,sector) VALUES $ops") or die(mysql_error());
	if($bbs) {
		mysql_query("INSERT	INTO user_bb(user,sessionid,sector) VALUES $bbs") or die(mysql_error());
	setmsg("Your profile was updated","your_adverts.php");
else {

	setmsg("Errors were found in the information below - please check and try again","critical",$referer);

Solved - it was redirecting to itself and therefore wiping out $_POST because of a missing parameter in one of the functions.