Directory  FAQ   Search   Register   Log in to check your private messages   Log in 

Form processing probs with PHP


 
Post new topic in Website Development   Reply to topic in Form processing probs with PHP    Hyderabad Forums -> Website Development

View previous topic :: View next topic  
Author Form processing probs with PHP
student123
Newbie
Newbie


Joined: 26 May 2006
Posts: 3

Posted: Fri May 26, 2006 10:32 pm    Post subject: Form processing probs with PHP Reply with quote

I've got a form, and everything works great ... sort of. When you hit submit, if you have a blank file, everything works great. And keeps working great. But as soon as I modify and reupload the csv file, it messes up on me. When I hit submit, it goes through the motions of sending, but then stops and stays at the page. Essentially it doesn't do anything. But as soon as I change the csv file back to blank, it works great again. The problem is, I have all this data (very long form) and I do not want to have to rekey in the data. I could just copy and paste into a blank file, but that makes the thing not work again. Any ideas?

Here is the code that processes it:
Quote:
// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead
// of $_FILES.

$uploaddir = '../profiles/gbimages/';
//Maxfile size
$maxfilesize = 81920;
// check if there was a file uploaded

// if it was, go ahead with other checks
if ($_FILES['userfile']['size'] > $maxfilesize) {
$error = "your image file was too large. Please hit your back button on your browser and use a smaller image.
";
print "$error";
unlink($_FILES['userfile']['tmp_name']);
exit;
}
else{
//End of max filesize

//Does person exist?
$match = "$FName"; // what we're looking for
$index = 0; // the field in which to look for $match, where the first value on a row of comma separated values is at index 0
$fp = fopen("answers.csv", "r");
$line_data = file("answers.csv");

while($row = fgetcsv($fp,100))
{
if ($row[$index] == $match)
{
$found = $row;
break;
}
}

fclose($fp);


if (is_array($found))
{
print "I'm sorry, but someone has already submitted their profile using that name. Email the webmaster of the BMP for help.";
}
else
{
//Does person exist? - Other file
$match = "$FName"; // what we're looking for
$index = 0; // the field in which to look for $match, where the first value on a row of comma separated values is at index 0
$fp1 = fopen("exec.csv", "r");
$line_data1 = file("exec.csv");

while($row1 = fgetcsv($fp1,500))
{
if ($row1[$index] == $match)
{
$found = $row1;
break;
}
}

fclose($fp1);


if (is_array($found))
{
print "I'm sorry, but someone has already submitted their profile using that name. Email the webmaster of the BMP for help.";
}
else
{


//End of person exist

//added stuff about type check
if (is_uploaded_file($_FILES['userfile']['tmp_name']))
{
$ext = strrchr($_FILES['userfile']['name'], ".");
if ($ext != ".gif" AND $ext != ".jpg" AND $ext != ".jpeg" AND $ext != ".bmp" AND $ext != ".GIF" AND $ext != ".JPG" AND $ext != ".JPEG" AND $ext != ".BMP") {
$error = "your file was not an unacceptable type. Please use a jpg, gif, or bmp.
";
unlink($_FILES['userfile']['tmp_name']);
print "$error";}
//end of stuff about type check
else {$uploadfile = $uploaddir . $_FILES['userfile']['name'];


print "
";

if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
print '

';
print "File is valid, and was successfully uploaded.";
print '

';
print "Here's some more debugging info:\n";
print_r($_FILES);
print '

';
} else {
print "Possible file upload attack! Here's some debugging info:\n";
print_r($_FILES);
}
print "
";
//added change name thing//
$rename = $FName; //or $rename =
$username;
$file_name = $_FILES['userfile']['name'];
$read_extension = explode(".", $file_name);
$ext = $read_extension[1];
$newfilename = str_replace(' ', '_', $FName . "." . $ext);
$htmlname = str_replace(' ', '_', $FName . ".html");
rename($uploaddir . $file_name, $uploaddir . $newfilename);
chmod($uploaddir . $newfilename , 0644);
//end of added change name thing
}}
//csv stuff
$quotew = str_replace('"','""',$quote);
$writestring = "\"" . $FName . "\",\"" . $Conc . "\",\"" . $Posi . "\",\"" . $Year . "\",\"" . $email . "\",\"" . $courses . "\",\"" . $newfilename . "\",\"" . $htmlname . "\",\"" . $FavCours . "\",\"" . $MemMoment . "\",\"" . $WhyChoose . "\",\"" . $WhereCareer . "\",\"" . $word . "\",\"" . $pasttime . "\",\"" . $quotew . "\",\"" . $movie . "\",\"" . $book . "\",\"" . $song . "\",\"" . $webpage . "\",\"" . $c1 . "\",\"" . $c2 . "\",\"" . $c3 . "\",\"" . $c4 . "\",\"" . $c5 . "\",\"" . $c6 . "\",\"" . $c7 . "\",\"" . $c8 . "\",\"" . $c9 . "\"\r\n"; //double quotes around values escaped and return and newline chars at end
$filepointer = fopen("answers.csv","a"); //appends to end of file
$mentorex = fopen("exec.csv","a");
if (($Posi == "mentor") OR ($Posi == "Mentor") OR ($Posi == "none") OR ($Posi == "n/a")OR ($Posi == "N/A") OR ($Posi == "None"))
{fwrite($filepointer,$writestring);
fclose($filepointer);}
else {
fwrite($mentorex,$writestring);
fclose($mentorex);}
print "";
print "Thank you for submitting your information. It will be added to the database shortly.
";
print "
click here in order to return to the BMP main page.";
print "
";
//end of csv stuff

}}}
?>

Anybody know what the heck is going on?
Back to top
Display posts from previous:   
Reply to topic in Form processing probs with PHP    Hyderabad Forums -> Website Development All times are GMT + 5.5 Hours
Page 1 of 1
Jump to:  


Backend by phpBB, Xand theme, © 2006 Hyderabad Forums World Ranking