RonnyNishimoto
08-19-2012, 11:46 PM
For a web application, I'm trying to create buttons that puts either 0 or 1 into a file. However, for some reason it only works once on the page (only works once for one button, then it doesn't work). (I'm guessing because you are only allowed to have 1 php request?).
Even when I add a window.location(); to reload the page, it submits old data. When I click the button for "0" (then it reloads), then I click the button for "1", it still writes to the file "0" for some reason.
Is there a way to make this work? (Reloading is fine, but if there is a way without, I would love to learn).
<?php
$test = "test.txt";
?>
<script>
$(document).ready(function(){
$('#0-button').click(function(){
<?php
$test1 = "0";
file_put_contents($test, $test1);
?>
});
$('#1-button').click(function(){
<?php
$test2 = "1";
file_put_contents($test, $test2);
?>
});
});
</script>
<button type="button" id="0-button">0</button>
<button type="button" id="1-button">1</button>
I really appreciate any help I can get, this is uncharted territory for me! :D
Even when I add a window.location(); to reload the page, it submits old data. When I click the button for "0" (then it reloads), then I click the button for "1", it still writes to the file "0" for some reason.
Is there a way to make this work? (Reloading is fine, but if there is a way without, I would love to learn).
<?php
$test = "test.txt";
?>
<script>
$(document).ready(function(){
$('#0-button').click(function(){
<?php
$test1 = "0";
file_put_contents($test, $test1);
?>
});
$('#1-button').click(function(){
<?php
$test2 = "1";
file_put_contents($test, $test2);
?>
});
});
</script>
<button type="button" id="0-button">0</button>
<button type="button" id="1-button">1</button>
I really appreciate any help I can get, this is uncharted territory for me! :D