Jump to content

Recommended Posts

Having trouble with my script seems like the if is bypassed staright into the else statement.  I have no idea what is wrong.  I think the problem is in the for loop not setting the $process to true.  However nothing after the if statement works; seems like it just goes straight to the else.  Just to make things clear im talking about if ($process==TRUE) statement.

 

Thanks Again

Grodo

 

 

 

// Ok lets validate some parameters! With error reporting!
$error = 0;
//We make an array to hold the error code information
$errorcodes = array('ok', 'ok', 'ok', 'ok', 'ok', 'ok');
if ($db_name == "") {
	$errorcodes[0] = ename;
	$error = 1;
}
if ($db_snumber == "") {
	$errorcodes[1] = esnumber;
	$error = 1;
}
if ($db_city == "") {
	$errorcodes[2] = ecity;
	$error = 1;
}
if ($db_state == "") {
	$errorcodes[3] = estate;
	$error = 1;
}
if ($db_zip == "") {
	$errorcodes[4] = ezip;
	$error = 1;
}
if ($db_country == "") {
	$errorcodes[5] = ecountry;
	$error = 1;
}

// Code that gives the ok to process
for ( $i = 0; $i<6; $i++ ) {
	if ( $errorcodes[$i] == "ok" && $error == "0" ) {
		$process == TRUE;
	} else {
		$process == FALSE;
	}
}	

             // This is the if statement that tells script to write
if ($process==TRUE)
{

	//Lets Try To Open Our All Data Campaign File
	$csv_alldata = "alldata.csv";
	if (is_writable($csv_alldata)) {
		if (!$csv_alldatahandle = fopen($csv_alldata,"a")) {
			echo "<p>Cannot open file $csv_alldata</p>";
			exit;
		}
	}
	// Alright! Its time to start writing
	// Writing All Data Name, Company, Email, Phone, And Fax
	$csv_itemalldata = "\"$db_name\",\"$db_company\",\"$db_email\",\"$db_phone\",\"$db_snumber\",\"$db_address2\",\"$db_city\",\"$db_state\",\"$db_country\",\"$db_zip\",\"$db_fax\"\n";

	if (is_writable($csv_alldata)) {
		if (fwrite($csv_alldatahandle, $csv_itemalldata) === FALSE) {
		echo "Cannot write to file $csv_alldata";
		exit; 
		}
	}
	// Lets Close The File
	fclose($csv_alldatahandle);

}
 else {
 // Lovely Error Codes :-)

	if ( $errorcodes[0] == "ename")
		{print "<font color =red><b><ul type=circle><li>State / Territory Field Missing<br></font></b></ul></li>";}	
	if ( $errorcodes[1] == "esnumber")
		{print "<font color =red><b><ul type=circle><li>Street Number Missing<br></font></b></ul></li>";}
	if ( $errorcodes[2] == "ecity")
		{print "<font color =red><b><ul type=circle><li>City Field Missing<br></font></b></ul></li>";}
	if ( $errorcodes[3] == "estate")
		{print "<font color =red><b><ul type=circle><li>State Field Missing<br></font></b></ul></li>";}
	if ( $errorcodes[4] == "ezip" )
		{print "<font color =red><b><ul type=circle><li>Postal Code Field Missing<br></font></b></ul></li>";}
	if ( $errorcodes[5] == "ecountry")
		{print "<font color =red><b><ul type=circle><li>Country Field Missing<br></font></b></ul></li>";}
	// SET Html code to a String
	$htmlcode = '<html>just some html code';
	if ($error=="1") {
		print($htmlcode);
		print "<body bgcolor=#ffffcc>";
	}
}

Link to comment
https://forums.phpfreaks.com/topic/62699-solved-mmmm-if-else-error/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.