I am getting an error in this code, simple fix i'm sure.

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

User avatar
akimm
Forum Contributor
Posts: 460
Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh

I am getting an error in this code, simple fix i'm sure.

Post by akimm »

Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /nfs/cust/8/25/05/650528/web/add_art.php on line 40

Code: Select all

$dude = fopen($fileName, 'w') or die("can't open file");
 // open the file or kill the script and show error 
$numBytes = fwrite($dude, $_POST['name'] && $_POST['email'] && $_POST['article'] "); 
// Write to the file with fwrite now 
// FWRITE LINE BELOW IS THE LINE CAUSNG ERROR, BEFORE THAT FCLOSE WAS FOR SOME REASON.
fwrite("/article/article[$i].txt") 
// Close the file handle 
fclose($dude);
 } 
}
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Re: I am getting an error in this code, simple fix i'm sure.

Post by tecktalkcm0391 »

akimm wrote:Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /nfs/cust/8/25/05/650528/web/add_art.php on line 40

Code: Select all

$dude = fopen($fileName, 'w') or die("can't open file");
 // open the file or kill the script and show error 
$numBytes = fwrite($dude, $_POST['name'] && $_POST['email'] && $_POST['article'] "); 
// Write to the file with fwrite now 
// FWRITE LINE BELOW IS THE LINE CAUSNG ERROR, BEFORE THAT FCLOSE WAS FOR SOME REASON.
fwrite("/article/article[$i].txt") 
// Close the file handle 
fclose($dude);
 } 
}
Try this:

Code: Select all

$dude = fopen($fileName, 'w') or die("can't open file");
// what to write
$write =  $_POST['name'].''. $_POST['email'].''. $_POST['article'] .''; 
// open the file or kill the script and show error 
$numBytes = fwrite($dude, $write); 
// Write to the file with fwrite now 
// FWRITE LINE BELOW IS THE LINE CAUSNG ERROR, BEFORE THAT FCLOSE WAS FOR SOME REASON.
fwrite("/article/article[$i].txt") 
// Close the file handle 
fclose($dude);
 } 
}
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Code: Select all

<?php
$dude = fopen($fileName, 'w') or die("can't open file");

// open the file or kill the script and show error
$numBytes = fwrite($dude, $_POST['name'] . ' ' . $_POST['email'] . ' ' . $_POST['article']);
/*********************************************
* The above line was causing the error with 
* the phantom double quote just before the closing 
* parenthesis
*********************************************/

// Write to the file with fwrite now
// FWRITE LINE BELOW IS THE LINE CAUSNG ERROR, BEFORE THAT FCLOSE WAS FOR SOME REASON.
fwrite("/article/article[$i].txt")
// Close the file handle
fclose($dude);
?>
User avatar
technofreak
Forum Commoner
Posts: 74
Joined: Thu Jun 01, 2006 12:30 am
Location: Chennai, India
Contact:

Re: I am getting an error in this code, simple fix i'm sure.

Post by technofreak »

akimm wrote:Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /nfs/cust/8/25/05/650528/web/add_art.php on line 40

Code: Select all

$dude = fopen($fileName, 'w') or die("can't open file");
 // open the file or kill the script and show error 
$numBytes = fwrite($dude, $_POST['name'] && $_POST['email'] && $_POST['article'] "); 
// Write to the file with fwrite now 
// FWRITE LINE BELOW IS THE LINE CAUSNG ERROR, BEFORE THAT FCLOSE WAS FOR SOME REASON.
fwrite("/article/article[$i].txt") 
// Close the file handle 
fclose($dude);
 } 
}

Think you have missed the semicolon after your --> fwrite("/article/article[$i].txt") ?! It should have been,

Code: Select all

fwrite("/article/article[$i].txt");

Was it in this post or was it in your code itself ?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Sweet, I am a completely blind fool. :oops: I missed that semicolon also.
User avatar
akimm
Forum Contributor
Posts: 460
Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh

wow, thanks all for the expediant response.

Post by akimm »

I am very greatful, as I'm blinder than all of you even everah so yea...
User avatar
akimm
Forum Contributor
Posts: 460
Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh

still an error

Post by akimm »

Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /nfs/cust/8/25/05/650528/web/add_art.php on line 41


fwrite("/article/article[$i].txt")
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

You got rid of the double quote at the end of the line, added the semicolon that was missing and made sure to close all brackets?
User avatar
akimm
Forum Contributor
Posts: 460
Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh

Everah

Post by akimm »

My code thus far after your improves and others imrpoves is this

Code: Select all

$dude = fopen($fileName, 'w') or die("can't open file"); 
 // open the file or kill the script and show error 
$numBytes = fwrite($dude, $_POST['name'] . $_POST['email'] . $_POST['article']); 
// Write to the file with fwrite now 
fwrite(article/article[$i].txt)
// Close the file handle 
fclose($dude); 
 } 
} 
?>
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post by tecktalkcm0391 »

Everah wrote:Sweet, I am a completely blind fool. :oops: I missed that semicolon also.


Me too. I missed that! :oops:
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post by tecktalkcm0391 »

akimm wrote:My code thus far after your improves and others imrpoves is this

Code: Select all

$dude = fopen($fileName, 'w') or die("can't open file"); 
 // open the file or kill the script and show error 
$numBytes = fwrite($dude, $_POST['name'] . $_POST['email'] . $_POST['article']); 
// Write to the file with fwrite now 
fwrite(article/article[$i].txt)
// Close the file handle 
fclose($dude); 
 } 
} 
?>
is it working then?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Add the semicolon...

Code: Select all

<?php
dude = fopen($fileName, 'w') or die("can't open file");
 // open the file or kill the script and show error
$numBytes = fwrite($dude, $_POST['name'] . $_POST['email'] . $_POST['article']);
// Write to the file with fwrite now
fwrite(article/article[$i].txt);
// Close the file handle
fclose($dude); 
?>
Robert Plank
Forum Contributor
Posts: 110
Joined: Sun Dec 26, 2004 9:04 pm
Contact:

Post by Robert Plank »

Uhh, and quotes?

Code: Select all

fwrite("article/article[$i].txt");
User avatar
akimm
Forum Contributor
Posts: 460
Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh

A new error

Post by akimm »

it said I couldn't concoctanate .txt, I did this because I wanted to have [$i] a for loop that iterates (supposedly) each new article that is submitted, I created a variable $ext to handle the .txt file.



Parse error: parse error, unexpected T_STRING in /nfs/cust/8/25/05/650528/web/add_art.php on line 41

Code: Select all

$dude = fopen($fileName, 'w') or die("can't open file"); 
 // open the file or kill the script and show error 
$numBytes = fwrite($dude, $_POST['name'] . $_POST['email'] . $_POST['article']); 
// Write to the file with fwrite now 
$ext = '.txt'
fwrite(article/article . [$i] . $ext); 
// Close the file handle 
fclose($dude); 
?>
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Re: A new error

Post by tecktalkcm0391 »

akimm wrote:it said I couldn't concoctanate .txt, I did this because I wanted to have [$i] a for loop that iterates (supposedly) each new article that is submitted, I created a variable $ext to handle the .txt file.



Parse error: parse error, unexpected T_STRING in /nfs/cust/8/25/05/650528/web/add_art.php on line 41

Code: Select all

$dude = fopen($fileName, 'w') or die("can't open file"); 
 // open the file or kill the script and show error 
$numBytes = fwrite($dude, $_POST['name'] . $_POST['email'] . $_POST['article']); 
// Write to the file with fwrite now 
$ext = '.txt'
fwrite(article/article . [$i] . $ext); 
// Close the file handle 
fclose($dude); 
?>
Try this:

Code: Select all

$dude = fopen($fileName, 'w') or die("can't open file"); 
// open the file or kill the script and show error 
$write = ''. $_POST['name'] . $_POST['email'] . $_POST['article'] .'';
// create what to write 
// I suggest this instead of putting it directly in the fwrite();
$numBytes = fwrite($dude, $write); 
// Write to the file with fwrite now 
$ext = '.txt';
fwrite("article/article . [$i] . $ext"); 
// Close the file handle 
fclose($dude); 
?>
Post Reply