/    Sign up×
Community /Pin to ProfileBookmark

PHP syntax errors

Hi,

I have a php based enquiry form on my website.
As well as sending the enquiry by email, I want to store the enquiry on the website in a csv file.

I pulled a bit of coding from another php script I have & added the code to my mail.php3 file (at the end of the post).

It fails on 2 lines:
open(LOGFILE, “>>$logfile”) or die “Can’t open $logfile: $!”;
and
print LOGFILE “$date2,$name,$hphone,$wphone,$mobile,$convenient,$email,$hours,$type,$date,$sex,$receptions,$bedrooms,$bathrooms,$ironing,$pets,$commentsn”;

I can’t see anything wrong with them!

=================
<?php

$name = $_REQUEST[‘name’];
$address = $_
REQUEST[‘address’];
$hphone = $_REQUEST[‘housephone’];
$wphone = $_
REQUEST[‘wphone’];
$mobile = $_REQUEST[‘mobile’];
$convenient = $_
REQUEST[‘convenient’];
$email = $_REQUEST[’email’];
$hours = $_
REQUEST[‘hours’];
$type = $_REQUEST[‘type’];
$date = $_
REQUEST[‘start’];
$sex = $_REQUEST[‘sex’];
$receptions = $_
REQUEST[‘receptions’];
$bedrooms = $_REQUEST[‘bedrooms’];
$bathrooms = $_
REQUEST[‘bathrooms’];
$ironing = $_REQUEST[‘ironing’];
$pets = $_
REQUEST[‘pets’];
$comments = $_REQUEST[‘comments’];
$logfile = “enquirylogs/enquiry.csv”;

$adminaddress = “[email protected]“;

$sitename = “Maid2Clean”;

$mail = mail(“$adminaddress”,”Client Request from maid2clean.org.uk”,

“*******************************************************************************
Name: $name
Home Phone: $hphone
Work Phone: $wphone
Mobile: $mobile
Time to Call: $convenient
Email: $email
HoursRequired: $hours
Clean Type: $type
Start Date: $date
MaleFemale cleaner: $sex
Receptions: $receptions
Bedrooms: $bedrooms
Bathrooms: $bathrooms
Ironing Required: $ironing
Any Pets: $pets

Address:

$address

Comments:

$comments”,”FROM:$adminaddress”);

$date2 = `date`;
chomp($date2);
open(LOGFILE, “>>$logfile”) or die “Can’t open $logfile: $!”;
flock(LOGFILE,2);
seek(LOGFILE,0,2);
print LOGFILE “$date2,$name,$hphone,$wphone,$mobile,$convenient,$email,$hours,$type,$date,$sex,$receptions,$bedrooms,$bathrooms,$ironing,$pets,$commentsn”;
flock(LOGFILE,8);
close LOGFILE;

if($mail)
{header( “Location: http://www.maid2clean.org.uk/thanks.html” ); }
else
{print “There was an error sending your enquiry, please try again.”; }
?>

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@SyCoDec 02.2008 — You say you've pulled some code from another file possibly from another directory, is $logfile value still the correct location?

(You might want to ask an admin to remove your email address. The 'report post' button will get their attention.)
Copy linkTweet thisAlerts:
@GraemePauthorDec 02.2008 — You say you've pulled some code from another file possibly from another directory, is $logfile value still the correct location?

(You might want to ask an admin to remove your email address. The 'report post' button will get their attention.)[/QUOTE]


Hi, I set $logfile here:

$logfile = "enquirylogs/enquiry.csv";

The code is from another completely unrelated website to do a lookup & works fine.

When I use the above code, I get:

Parse error: syntax error, unexpected '"' in /home/sites/xxxxxxxxxxxxx/public_html/mail.php3 on line 65

Line 65 is: open(LOGFILE, ">>$logfile") or die "Can't open $logfile: $!";

If I change it to : open(LOGFILE, ">>$logfile");

Then it gets past this line and fails with:

Parse error: syntax error, unexpected '"' in /home/sites/xxxxxxxxxxx/public_html/mail.php3 on line 68

This line is: print LOGFILE "$date2,$name,$hphone,$wphone,$mobile,$convenient,$email,$hours,$type,$date,$sex,$receptions,$bedrooms,$bathrooms,$ironing,$pets,$commentsn";
Copy linkTweet thisAlerts:
@SyCoDec 02.2008 — die() is a function. Try wrapping the die messages in parenthesis.

[code=php]or die("message here");[/code]
Copy linkTweet thisAlerts:
@GraemePauthorDec 03.2008 — Hi, that worked thanks (although I now can't understand why it works in the other script - doh!). It now gets past this point.

Can you see anything wrong with the print statement?

Is there an easier way to do this?
Copy linkTweet thisAlerts:
@SyCoDec 03.2008 — [B]$bedroo ms [/B]should probably be [B]$bedrooms[/B]

If that's not it what errors are you getting?
Copy linkTweet thisAlerts:
@GraemePauthorDec 03.2008 — Hi,

Hadn't noticed that!

I still get:

[B]Parse error: syntax error, unexpected '"' in /home/sites/maid2clean.org.uk/public_html/mail.php3 on line 68[/B]

Even if I change that line to

[B]print LOGFILE "$date2n"; [/B]

I get exactly the same error.

If I remove that line completely, I get:

[B]Fatal error: Call to undefined function: chomp() in /home/sites/maid2clean.org.uk/public_html/mail.php3 on line 64[/B]
Copy linkTweet thisAlerts:
@SyCoDec 03.2008 — date is neither a unix timestamp or a SQL timestamp, it's system date/time so may possibly contain a " . You can echo $date to see what you're getting.

Try replacing

[code=php]$date=date;[/code]
with
[code=php]$date=date("Y:m:d H:m:s",time());[/code]

You need to include the functions from wherever you got the files from. chomp() is a custom function not part of PHP.
×

Success!

Help @GraemeP spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.3,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...