Ive got a form that submits a voluntary contribution from staff for a charity fund.
They enter their name, and the amount from a drop down box.
I have it writing to a file, delimited by ";"
Sometimes, 2 new lines of information are written to the file instead of one, so the record is duplicated in the file
eg
"staffname";"10";"euro";"3.1.1.110";"05/12/03";"14.12"
"staffname";"10";"euro";"3.1.1.110";"05/12/03";"14.12"
Can anyone suggest a way to stop this.
I have tested this myself, and I have only pressed the submit image (i have an image button to submit the form) only once
I am stumped!
Thanks
Adrian.
<?php
$datestring = date("d/m/y");
$timestring = date("H.i.s");
//get the IP address of the computer that makes the donation.
if(getenv("HTTP_X_FORWARDED_FOR")){
$ip=getenv("HTTP_X_FORWARDED_FOR");
}
else{
$ip=getenv("REMOTE_ADDR");
}
$fp = fopen("fundlist.txt", "a");
// Check if can write to file
if (!$fp) {
print 'Could not open desired file for writing';
}
$donationvalue = 0;
$name = $HTTP_POST_VARS['name'];
$amount = $HTTP_POST_VARS['amount'];
$currency = $HTTP_POST_VARS['currency'];
$amounteuro = $HTTP_POST_VARS['amounteuro'];
$amountpound = $HTTP_POST_VARS['amountpound'];
if ($currency == "euro") { $donationvalue = ($amounteuro * 10); $currsign = "€";}
if ($currency == "pound") { $donationvalue = ($amountpound * 7); $currsign = "£";}
// Set what will be written to file
$outputstring = "\"$name\";\"$donationvalue\";\"$currency\";\"$ip\";\"$datestring\";\"$timestring\"\n";
echo $outputstring;
// Finally, write to file
fwrite($fp, $outputstring);
// Close the written file
fclose($fp);
?>