Page 1 of 2

parse error in submit.php on line 10

Posted: Mon Nov 24, 2003 10:48 pm
by OuchMedia
I'm new to PHP and i'm trying to write a script to allow me to have information from a form saved to a file....i keep getting the following error:

Parse error: parse error in /home/sites/site46/web/New/submit.php on line 10

I am attaching the script...all help is appreciated, as I don't know a lot about PHP yet and I am unable to figure out the problem. Thanks in advance for the help.

html
head
title>Untitled Document</title
/head
body

?
$fp = fopen("$quotes.txt", "a");
fwrite($fp, $outputstring);
$outputstring = $date."\n". Name .$name."\n" Title $title."\n" Company $company."\n" Address $address."\n" City, State $location."\n" Phone $phone."\n" Email $email."\n" Text $description."\n";

fclose($fp);
?

h1>ouch media</h1
h2>form results</h2
?
echo "<p>form processed.";
?


/body
/html

Posted: Mon Nov 24, 2003 11:27 pm
by DuFF
Umm, what happened to the "<" and ">"'s? :(

Could you repost the script using the

Code: Select all

or

Code: Select all

tags?  And also point out line 10?  Sometimes there are extra blank lines.

Right now the #1 error I can see is that you have fwrite($fp, $outputstring);  and then the next line has the $outputstring.  You have to have the $outputstring line before writing it to the file.  When you call fwrite, the outputstring contains nothing.

Posted: Mon Nov 24, 2003 11:36 pm
by OuchMedia
Here is the script again. I put in the line numbers too.

Code: Select all

1 <html>
2 <head>
3 <title>Untitled Document</title>
4 </head>
5 <body>
6
7 <?
8 $fp = fopen("$quotes.txt", "a");
9 fwrite($fp, $outputstring);
10 $outputstring = $date."\n". Name .$name."\n" Title $title."\n" Company $company."\n" Address $address."\n" City, State $location."\n" Phone $phone."\n" Email $email."\n" Text $description."\n";
11
12 fclose($fp);
13 ?>
14 
15 <h1>ouch media</h1>
16 <h2>form results</h2>
17 <?
18	echo "<p>form processed.";
19 ?>
20
21
22 </body>
23 </html>

Posted: Mon Nov 24, 2003 11:43 pm
by Nay
It'll make much more sense if you put it in [ php ] and [/ php ] tags since the color of the entire script would be red. Anyhow, you missed a "." somewhere in the script. And also, $outputstring should be declared before the fwrite. Here's a better way:

Code: Select all

<html>

   <head>
      <title>Untitled Document</title>
   </head>

   <body>
<?php

$outputstring = <<< OUT
$date
Name $name
Title $title
Company $company
Address $address
City, State $location
Phone $phone
Email $email
Text $description
OUT;

$fp = fopen("$quotes.txt", "a");
$fw = fwrite($fp, $outputstring);
fclose($fp);
?>
      <h1>ouch media</h1>
      <h2>form results</h2>
<?php
echo "<p>form processed.</p>";
?>
   </body>
</html>
-Nay

Posted: Tue Nov 25, 2003 12:03 am
by OuchMedia
i copied the code exactly as you had it and put it into a brand new script page and i now get an error on line 9(which follows)

Code: Select all

<?php
9 $outputstring = <<< OUT
?>

Posted: Tue Nov 25, 2003 12:07 am
by Nay
What's the error?

-Nay

Posted: Tue Nov 25, 2003 12:10 am
by OuchMedia
Parse error: parse error in /home/sites/site46/web/New/submit.php on line 9

Posted: Tue Nov 25, 2003 12:15 am
by Nay
mMm............it shouldn't be any error, I did test it out. Can you post your script now PLUSE all the errors. And just on the other note, do you have permissions to write to that file?

-Nay

Posted: Tue Nov 25, 2003 12:21 am
by OuchMedia
here is the script:

Code: Select all

<?php
<html> 

   <head> 
      <title>Untitled Document</title> 
   </head> 

   <body> 
<?php 
$outputstring = <<< OUT 
$date 
Name $name 
Title $title 
Company $company 
Address $address 
City, State $location 
Phone $phone 
Email $email 
Text $description 
OUT; 

$fp = fopen("$quotes.txt", "a"); 
$fw = fwrite($fp, $outputstring); 
fclose($fp); 
?> 
      <h1>ouch media</h1> 
      <h2>form results</h2> 
<?php 
echo "<p>form processed.</p>"; 
?> 
   </body> 
</html>
?>
Here is the error:
Parse error: parse error in /home/sites/site46/web/New/submit.php on line 9

I'm not sure about the question on "permission"; i'm the aministrator. this is a "virtual server". I just checked, and embedded PHP is enabled. Not sure if any of this info helps.

Posted: Tue Nov 25, 2003 12:22 am
by OuchMedia
well, i'm off to bed for the evening...thank you very much for your help! i'll be back on tomorrow to continue my quest to solve this problem. thanks again for the help!!!

Posted: Tue Nov 25, 2003 12:30 am
by Nay
OuchMedia wrote:here is the script:

Code: Select all

<?php
<html> 

   <head> 
      <title>Untitled Document</title> 
   </head> 

   <body> 
<?php 
$outputstring = <<< OUT 
$date 
Name $name 
Title $title 
Company $company 
Address $address 
City, State $location 
Phone $phone 
Email $email 
Text $description 
OUT; 

$fp = fopen("$quotes.txt", "a"); 
$fw = fwrite($fp, $outputstring); 
fclose($fp); 
?> 
      <h1>ouch media</h1> 
      <h2>form results</h2> 
<?php 
echo "<p>form processed.</p>"; 
?> 
   </body> 
</html>
?>
Here is the error:
Parse error: parse error in /home/sites/site46/web/New/submit.php on line 9

I'm not sure about the question on "permission"; i'm the aministrator. this is a "virtual server". I just checked, and embedded PHP is enabled. Not sure if any of this info helps.
..................that was not exactly my script was it? You should remove the <php at the first line. And also the ?> at the last.

-Nay

Posted: Tue Nov 25, 2003 12:51 am
by KDesigns
If this file is basically acting as your form controller than data is getting sent to this file from a previous file, say "form.php", correct? Remember that your variables are only defined for that specific file unless they are set as constants or are sent to the submit.php file by POST command. Also, the "/n" is a new line character but it will only show in the source code. If you actually want to have a carriage return you need to use "/r".

Use this below and you should have no problem. All you'll need to do is actually change where the variables are defined by putting in the actual form field name. Feel free to shoot me and email or private message if you need a little help. I've tested this on my local server here and received no parse errors. Let me know if it works!

------------------------
Submit.php
------------------------

<html>
<head>
<title>Untitled Document</title>
</head>
<body>

<?php

//Define your variables here
$date = $_POST['formfieldname'];
$name = $_POST['formfieldname'];
$company = $_POST['formfieldname'];
$address = $_POST['formfieldname'];
$location = $_POST['formfieldname'];
$phone = $_POST['formfieldname'];
$email = $_POST['formfieldname'];
$description = $_POST['formfieldname'];
//The above define your variables sent from your "form.php" file

$fp = fopen("$quotes.txt", "a");
$outputstring = "$date.\n\r\r. Name .$name.\n\r\r Title $title.\n\r\r Company $company.\n\r\r Address $address.\n\r\r City, State $location.\n\r\r Phone $phone.\n\r\r Email $email.\n\r\r Text $description.\n\r\r";
fwrite($fp, $outputstring);
fclose($fp);
?>

<h1>ouch media</h1>
<h2>form results</h2>
<?
echo "<p>form processed.";
?>

</body>
</html>

Posted: Tue Nov 25, 2003 2:34 am
by Nay

Code: Select all

$outputstring = "$date.\n\r\r. Name .$name.\n\r\r Title $title.\n\r\r Company $company.\n\r\r Address $address.\n\r\r City, State $location.\n\r\r Phone $phone.\n\r\r Email $email.\n\r\r Text $description.\n\r\r";
That's not proper, and if you didn't close the quotes, you wouldn't need the dots <_<.

-Nay

Posted: Tue Nov 25, 2003 7:34 am
by KDesigns
The dots are not for programming sake. They are there to end a sentence. In this case they are not dots, they're periods.

Posted: Tue Nov 25, 2003 8:06 am
by twigletmac
With regards to the parse error - I have copied and pasted all the code posted and none of it gave a parse error. In case a hidden character has worked its way into your file I would empty the file and copy and paste code in from the forum.

Mac