parse error in submit.php on line 10
Moderator: General Moderators
parse error in submit.php on line 10
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
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
Umm, what happened to the "<" and ">"'s?
Could you repost the script using the
Could you repost the script using the
Code: Select all
orCode: 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.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>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:
-Nay
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>
Last edited by Nay on Tue Nov 25, 2003 12:13 am, edited 1 time in total.
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
?>here is the script:
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.
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>
?>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.OuchMedia wrote:here is the script:Here is the error: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> ?>
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.
-Nay
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>
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>
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";-Nay
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK