Apologies if this question is duplicated, I have however not found an obvious answer to my question. I am a complete novice with php, be kind! When I load the following code, it appears to run if(isset($_POST['test']))
even though I have not pressed the button "test"
. I only want the code to execute when I press the "test
" button. How do I resolve this?
<?php
if(isset($_POST['update'])) {
$content=simplexml_load_file("books.xml");
$value=$content->book->price;
$sum=$content->book->price;
}
if(isset($_POST['test'])) {
$content=simplexml_load_file("books.xml");
$value=$content->book->price;
$content->book->price = $value + 1.0;
$content->asXML("books.xml");
$sum=$content->book->price;
}
?>
<body>
<form method="post">
<input type="checkbox" id="i1check1" onchange="toggleDisabled(this.checked)"> Alarm 01
<input type="text" id="i1text1" name="i1" size="80" maxlength="128" value="<?php echo @$sum;?>"/>
<input type="submit" id="i1btn1" name="update" value="Update"/>
<input type="submit" id="i1btn2" name="test" value="Test"/>
</form>
<script>
function toggleDisabled(_checked) {
document.getElementById('i1text1').disabled = _checked ? false : true;
document.getElementById('i1btn1').disabled = _checked ? false : true;
}
</script>
</body>
Please Try This
if(isset($_POST['update']) && $_POST['update'] == "Update"){
$content=simplexml_load_file("books.xml");
$value=$content->book->price;
$sum=$content->book->price;
}
if(isset($_POST['test']) && $_POST['test'] == "Test"){
$content=simplexml_load_file("books.xml");
$value=$content->book->price;
$content->book->price = $value + 1.0;
$content->asXML("books.xml");
$sum=$content->book->price;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With