This is my test.php code
<input type="button" value="click me" name="my_btn" onclick="mybtn();">
<?php
echo("before is set");
if(isset($_POST['hello'])=="dear"){
echo("after is set true");
}
?>
<script src="vendor/jquery/jquery.min.js"></script>
<script>
function mybtn(){
$.ajax({
url:"http://localhost/mysites/php_two/test.php",
method:"post",
data:{hello:"dear"},
});
}
</script>
when button is clicked, page only shows
button icon + “before is set” text only.
But in Devtools network preview (in chrome browser), it shows
button icon +” before is setafter is set true”
please help me to fix this issue.
2
Answers
I think this want minimum 2 PHP pages 1st for show data and 2nd for creating data
show.php
data.php
You can’t mix
if(isset($_POST['hello'])=="dear")
because isset() takes a variable and check if it is set and not NULL which returns a boolean instead use it separate like this: