Hello all,
First off, I'm a php newbie; a very new newbie. I inherited a project to create a sweepstakes form where the users enter their information into the form fields and when they click Submit, the php script transfers the user's information to a .csv file. When I did this and tested it on our pre-production server, it worked perfectly. Once synchronized with our live production server, however, when a user clicks Submit he only gets an error stating "Cannot open file (****.csv)". Since it works on the dev server I was thinking maybe it was related to a permissions setting or something on the main server.
Has anyone ever encountered this, and/or, can anyone offer any possible solutions? I've always been a fast learner, but I need some serious help here. Many, many thanks in advance for your time.
Pixie.
<?php
// Receiving variables
@$pfw_ip= $SERVER['REMOTE_ADDR'];
@$firstname = addslashes($POST['firstname']);
@$lastname = addslashes($POST['lastname']);
@$address1 = addslashes($POST['address1']);
@$city = addslashes($POST['city']);
@$state = addslashes($POST['state']);
@$zip = addslashes($POST['zip']);
@$phone = addslashes($POST['phone']);
@$email = addslashes($POST['email']);
@$dob = addslashes($POST['dob']);
@$gender = addslashes($_POST['gender']);
// Validation
if (strlen($firstname) == 0 )
{
header("Location: error.htm");
exit;
}
if (strlen($lastname) == 0 )
{
header("Location: error.htm");
exit;
}
if (strlen($address1) == 0 )
{
header("Location: error.htm");
exit;
}
if (strlen($city) == 0 )
{
header("Location: error.htm");
exit;
}
if (strlen($state) == 0 )
{
header("Location: error.htm");
exit;
}
if (strlen($zip) == 0 )
{
header("Location: error.htm");
exit;
}
if (strlen($phone) == 0 )
{
header("Location: error.htm");
exit;
}
if (! ereg('[A-Za-z0-9-]+@[A-Za-z0-9-]+.[A-Za-z0-9_-]+', $email))
{
header("Location: error.htm");
exit;
}
if (strlen($email) == 0 )
{
header("Location: error.htm");
exit;
}
if (strlen($dob) == 0 )
{
header("Location: error.htm");
exit;
}
if (strlen($gender) == 0 )
{
header("Location: error.htm");
exit;
}
//saving record in a text file
$pfw_file_name = "***.csv";
$pfw_first_raw = "firstname,lastname,address1,city,state,zip,phone,email,dob,gender\r\n";
$pfw_values = "$firstname,$lastname,$address1,$city,$state,$zip,$phone,$email,$dob,$gender\r\n";
$pfw_is_first_row = false;
if(!file_exists($pfw_file_name))
{
$pfw_is_first_row = true ;
}
if (!$pfw_handle = fopen($pfw_file_name, 'a+')) {
die("Cannot open file ($pfw_file_name)");
exit;
}
if ($pfw_is_first_row)
{
if (fwrite($pfw_handle, $pfw_first_raw ) === FALSE) {
die("Cannot write to file ($pfw_filename)");
exit;
}
}
if (fwrite($pfw_handle, $pfw_values) === FALSE) {
die("Cannot write to file ($pfw_filename)");
exit;
}
fclose($pfw_handle);
header("Location: thankyou.htm");
?>