...

View Full Version : Is this possible?



Ranger56
08-30-2006, 12:41 AM
http://spiderseatbabies.com/test/

When I submit the form I want it to add the number to whatever is in the text file.

So if I put 4 into the form, and 46 was in the text file, it would go to 50 instead of 4.

index.php

<?php
$file = "m.txt";
$file_open = fopen($file, 'a+');
$theData = fread($file_open, filesize($file));
echo $theData;
?>


form.php

<?php
$file = "m.txt";
$somecontent = $_GET['add'];
if (is_writable($file)) {
if (!$handle = fopen($file, 'w+')) {
echo "Cannot open file ($file)";
exit;
}
if (fwrite($handle, $somecontent) === FALSE) {
echo "Cannot write to file ($file)";
exit;
}

echo "Added ($somecontent)";

fclose($handle);

} else {
echo "The file $file is not writable";
}
?>

Mwnciau
08-30-2006, 12:51 AM
<?php
$file = "m.txt";
$theData = file_get_contents($file);
$somecontent = $_GET['add'] + $theData;
if (is_writable($file)) {
if (!$handle = fopen($file, 'w+')) {
echo "Cannot open file ($file)";
exit;
}
if (fwrite($handle, $somecontent) === FALSE) {
echo "Cannot write to file ($file)";
exit;
}

echo "Added ($somecontent)";

fclose($handle);

} else {
echo "The file $file is not writable";
}
?>

Won't that work? it was basically what you had...

Ranger56
08-30-2006, 12:53 AM
I tried that but it doesn't work.

Mwnciau
08-30-2006, 12:59 AM
Is there an error or is the info in the file just wrong?

Ranger56
08-30-2006, 01:03 AM
Instead of adding, it just changes whatever is in the file to whatever you put in the form.

Mwnciau
08-30-2006, 01:09 AM
<?php
$file = "m.txt";
$theData = file_get_contents($file);
$somecontent = $_GET['add'] + $theData;
if (is_writable($file)) {
if (!$handle = fopen($file, 'w+')) {
echo "Cannot open file ($file)";
exit;
}
if (fwrite($handle, $somecontent) === FALSE) {
echo "Cannot write to file ($file)";
exit;
}

echo "Added ($_GET[add])";

fclose($handle);

} else {
echo "The file $file is not writable";
}
echo file_get_contents($file);
?> works for me =\

Ranger56
08-30-2006, 01:12 AM
Oh I thought it was the same with "+ $theData" added, didn't see the other stuff.

Thanks a lot, it works.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum