hi everybody.
obviously i am a bloddy beginner, so sorry for bothering you with such simple stuff, but here's my problem:
my aim is not to let somebody post the input twice, i.e. by hitting the submit button more than one time. in the following script i tried to arrange something to avoid it, but even if the recent input is exactly the same like the last one, it's written into the txt-file, but actually it shouldnt. i know there are more clever ways to solve this, but i just wanted to know why this doesnt work.
thanks
<FORM ACTION="<?=$PHP_SELF?>" METHOD="POST" NAME="Input_Device">
Your Input:<BR>
<INPUT TYPE="text" SIZE="30" NAME="input"><BR>
<BR>
<INPUT TYPE="submit" NAME="submit" VALUE="Post Input"><BR>
</FORM>
<?php
//i wanted to test if it's possible
//to avoid double posting via this script.
//but it won't work:
$input = file('input.txt');
$myarray = array_reverse($input);
if(!isset($_POST['input']))
{
$_POST['input'] = NULL;
}
elseif("$myarray[0]" == $_POST['input'])
//here i want to check if the recently posted input
//is euqal to the last posting
{
echo "No double posting!"; exit;
} else {
$inputdata = $_POST['input'] . "\r\n";
$file = fopen('input.txt','a+');
fwrite($file, $inputdata);
echo $_POST['input'];
fclose($file);
}
//so even if the last posted input ($myarray[0]) is
//equal to the recently input data, the script runs
//and writes the input into the file =(
//what's wrong?
?>