if {} else {}
Posted: Mon Feb 07, 2011 6:44 am
Hi, I'm having an if statement problem. This gives me a unexpected T_STRING on line 6 which points to the variables at the top. However what I don't get is that if there is no $_POST['upload'] this should be skipped and therefore offer no problem at least to open the page. Anyone have any ideas why I might be getting this error?
Code: Select all
<?php require_once('Connections/recommendingpeople.php'); ?>
<?php
if((isset($_POST['upload']) && $_FILES['userfile']['size']>0))
{
$fileName = $_FILES["userfile"]["name"];
$tmpName = $_FILES["userfile"]["tmp_name"];
$fileSize = $_FILES["userfile"]["size"];
$fileType = $_FILES["userfile"]["type"];
$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
}
include 'library/config.php';
include 'library/opendb.php';
mysql_select_db($database_recommendingpeople, $recommendingpeople);
$query = "INSERT INTO userphoto (name, size, type, content)".
"VALUES ('$fileName', '$fileSize', '$fileType', '$content')";
mysql_query($query) or die('Error, query failed');
include 'library/closedb.php';
echo "<br>File $fileName uploaded<br>";
}
else { echo:"there is no post"; }
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form method="post" enctype="multipart/form-data">
<table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
<tr>
<td width="246">
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
<input name="userfile" type="file" id="userfile">
</td>
<td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td>
</tr>
</table>
</form>
</body>
</html>