parse error in submit.php on line 10

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

OuchMedia
Forum Newbie
Posts: 11
Joined: Mon Nov 24, 2003 10:48 pm

parse error in submit.php on line 10

Post 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
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post 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.
OuchMedia
Forum Newbie
Posts: 11
Joined: Mon Nov 24, 2003 10:48 pm

Post 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>
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post 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
Last edited by Nay on Tue Nov 25, 2003 12:13 am, edited 1 time in total.
OuchMedia
Forum Newbie
Posts: 11
Joined: Mon Nov 24, 2003 10:48 pm

Post 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
?>
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

What's the error?

-Nay
OuchMedia
Forum Newbie
Posts: 11
Joined: Mon Nov 24, 2003 10:48 pm

Post by OuchMedia »

Parse error: parse error in /home/sites/site46/web/New/submit.php on line 9
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post 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
OuchMedia
Forum Newbie
Posts: 11
Joined: Mon Nov 24, 2003 10:48 pm

Post 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.
OuchMedia
Forum Newbie
Posts: 11
Joined: Mon Nov 24, 2003 10:48 pm

Post 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!!!
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post 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
KDesigns
Forum Newbie
Posts: 2
Joined: Tue Nov 25, 2003 12:51 am
Location: Western Maryland

Post 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>
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post 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
KDesigns
Forum Newbie
Posts: 2
Joined: Tue Nov 25, 2003 12:51 am
Location: Western Maryland

Post 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.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
Locked