Grodo Posted July 31, 2007 Share Posted July 31, 2007 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 More sharing options...
mdnghtblue Posted July 31, 2007 Share Posted July 31, 2007 if ( $errorcodes[$i] == "ok" && $error == "0" ) { Don't put quotes around the 0, it thinks you mean a string, when it's an integer. Link to comment https://forums.phpfreaks.com/topic/62699-solved-mmmm-if-else-error/#findComment-312058 Share on other sites More sharing options...
Grodo Posted July 31, 2007 Author Share Posted July 31, 2007 Hmmmmm still the same problem Link to comment https://forums.phpfreaks.com/topic/62699-solved-mmmm-if-else-error/#findComment-312088 Share on other sites More sharing options...
Grodo Posted July 31, 2007 Author Share Posted July 31, 2007 Figured it out the problem was that there was 2 equals. $process==True; removed one and it works mdnghtblue thank you for leading me in the right direction (well kind of) Link to comment https://forums.phpfreaks.com/topic/62699-solved-mmmm-if-else-error/#findComment-312096 Share on other sites More sharing options...
mdnghtblue Posted July 31, 2007 Share Posted July 31, 2007 Heh, no problem. Should've noticed that myself...>.< Link to comment https://forums.phpfreaks.com/topic/62699-solved-mmmm-if-else-error/#findComment-312098 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.