Page 1 of 1

if {} else {}

Posted: Mon Feb 07, 2011 6:44 am
by timoteo
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>

Re: if {} else {}

Posted: Mon Feb 07, 2011 7:18 am
by VladSun

Code: Select all

else { echo:"there is no post"; }

Re: if {} else {}

Posted: Mon Feb 07, 2011 8:54 am
by timoteo
Thanks, I did that but still the same:
Parse error: syntax error, unexpected T_STRING in /home/biomagn1/public_html/recommendingpeople.com/ya.php on line 6
What I don't get is that if there is no submit of the form this line should be skipped no? Or am I wrong. Or why am I wrong?

Re: if {} else {}

Posted: Mon Feb 07, 2011 9:07 am
by VladSun
I didn't fix it for you, just pointed at it. Taka a closer look at what you've written there.

Re: if {} else {}

Posted: Mon Feb 07, 2011 9:19 am
by timoteo
I tried

Code: Select all

else { echo "there is no post"; }
and I tried

Code: Select all

else {}
, but it all comes out the same

Re: if {} else {}

Posted: Mon Feb 07, 2011 9:33 am
by VladSun
Well, that was the only syntax error in this file. Are you sure it's not in library/config.php or library/opendb.php? Read the error message carefully and post it here.

Re: if {} else {}

Posted: Mon Feb 07, 2011 10:41 am
by timoteo
This was the error:
Parse error: syntax error, unexpected T_STRING in /home/biomagn1/public_html/recommendingpeople.com/ya.php on line 6
I've checked that file sharing is on. I don't know what else could be the issue. The table is in Innodb - that's not a problem is it? What else could I look for?

Re: if {} else {}

Posted: Mon Feb 07, 2011 10:49 am
by timoteo
I have a feeling that the problem is with variable $tmpName. If I remove that one the error moves along until $tmpname is needed. How can i get around it?

Re: if {} else {}

Posted: Mon Feb 07, 2011 11:08 am
by timoteo
I went into phpinfo and found this - Is this my problem?
upload_tmp_dir no value no value
.
If so how can I change this or work around this. I am using a remote shared server.

Re: if {} else {}

Posted: Mon Feb 07, 2011 11:17 am
by greyhoundcode
If it is shared hosting then perhaps your host has restricted your ability to upload files, for whatever reason. There are various ways to amend the upload_tmp_dir setting, if your host allows you to do so, take a look at the points listed here.

Re: if {} else {}

Posted: Mon Feb 07, 2011 2:12 pm
by timoteo
From what I have seen in the php manual the upload_tmp_dir with no value shouldn't be a problem. And yes I can change php settings with my host if needed, but I have no idea why this is not working
The temporary directory used for storing files when doing file upload. Must be writable by whatever user PHP is running as. If not specified PHP will use the system's default.

Re: if {} else {}

Posted: Tue Feb 08, 2011 5:51 am
by timoteo
I opened a new thread as the problem would seem to be diferent.
viewtopic.php?f=1&t=127508
If{} else{} seemed to be fine even if I do not understand exactly why the if{} was not skipping over the problem if there was no $_POST['upload']