if {} else {}

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
timoteo
Forum Contributor
Posts: 125
Joined: Sat Jan 08, 2011 6:46 am

if {} else {}

Post 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>
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: if {} else {}

Post by VladSun »

Code: Select all

else { echo:"there is no post"; }
There are 10 types of people in this world, those who understand binary and those who don't
timoteo
Forum Contributor
Posts: 125
Joined: Sat Jan 08, 2011 6:46 am

Re: if {} else {}

Post 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?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: if {} else {}

Post by VladSun »

I didn't fix it for you, just pointed at it. Taka a closer look at what you've written there.
There are 10 types of people in this world, those who understand binary and those who don't
timoteo
Forum Contributor
Posts: 125
Joined: Sat Jan 08, 2011 6:46 am

Re: if {} else {}

Post 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
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: if {} else {}

Post 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.
There are 10 types of people in this world, those who understand binary and those who don't
timoteo
Forum Contributor
Posts: 125
Joined: Sat Jan 08, 2011 6:46 am

Re: if {} else {}

Post 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?
timoteo
Forum Contributor
Posts: 125
Joined: Sat Jan 08, 2011 6:46 am

Re: if {} else {}

Post 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?
timoteo
Forum Contributor
Posts: 125
Joined: Sat Jan 08, 2011 6:46 am

Re: if {} else {}

Post 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.
User avatar
greyhoundcode
Forum Regular
Posts: 613
Joined: Mon Feb 11, 2008 4:22 am

Re: if {} else {}

Post 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.
timoteo
Forum Contributor
Posts: 125
Joined: Sat Jan 08, 2011 6:46 am

Re: if {} else {}

Post 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.
timoteo
Forum Contributor
Posts: 125
Joined: Sat Jan 08, 2011 6:46 am

Re: if {} else {}

Post 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']
Post Reply