Jump to content

Problem with if statement


samtwilliams

Recommended Posts

Hi All,

 

I have a problem with an if file exists block within my code;

 

// PROCCESS FORM
if (isset($_POST['Submit'])) {													// ISSET MAIN BLOCK
$uploadname = basename( $_FILES['uploaded']['name']);
$target = $target . basename( $_FILES['uploaded']['name']);
$clean = array();
$clean['name'] = mysql_real_escape_string($_POST['name']); 
$clean['type'] = mysql_real_escape_string($_POST['type']); 
$clean['handicap'] = mysql_real_escape_string($_POST['handicap']); 
$cldate = mysql_real_escape_string($_POST['closingdate']);
// CONVERT DATE from dd/mm/yyyy ro yyyy-mm-dd
list($d, $m, $y) = preg_split('/\//', $cldate);
$mydate = sprintf('%4d-%02d-%02d', $y, $m, $d);
$clean['closingdate'] = $mydate;($cldate);
// START THE FORM CHECKING
    if (isset($_SESSION['token']) && $_POST['token'] == $_SESSION['token']) {	// TOKEN CHECK
	foreach($_POST as $allvalues) { 										// FOREACH BLOCK
	if($allvalues == "") { 													// TEST FOR BLANKS IF BLOCK
	$warning = 'Error: One or more of the fields are blank';
	break;
	} else {															// **FOREACH ELSE
		if (file_exists($target)) {											// FILE CHECK IF BLOCK 
		$warning = "The file $uploadname already exists";
		} else {														// **FILE CHECK ELSE  
			if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) {
			$query_eventinsert = "INSERT INTO events (id, name, type, closingdate, handicaplimit, applicationurl) VALUES ('','"	.$clean['name']."','".$clean['type']."','".$clean['closingdate']."','".$clean['handicap']."','$uploadname')";
			mysql_query($query_eventinsert);
			$warning = 'Event added!';
			}
		}																	// FILE CHECK IF BLOCK 
	}																		// TEST FOR BLANKS IF BLOCK
}																			// FOREACH BLOCK
} else {																// **ISSET MAIN ELSE
$warning = 'Warning: You have tried to re-submit your last form entry, this would cause a duplicate!';
}																			// TOKEN CHECK
} 

 

Even if the file does not exists the code executes the following line

$warning = "The file $uploadname already exists";

Surely it should move to the else?

Link to comment
https://forums.phpfreaks.com/topic/167597-problem-with-if-statement/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.