Change value of a variable with PHP button [closed]

-2

I want to change the value of this variable.

$beg_j = $numjour; 

For this,

$beg_j = $numjour-1; 

button:

echo "<input type=button value=Change onclick=$beg_j-1>";
    
asked by anonymous 03.11.2014 / 00:11

2 answers

1

This is not possible. The php runs on the server and after running, everything is for the account of the client (browser).

When the browser makes a request to the server, php executes and returns the result (html) to the browser. This is their life cycle. It does not stay running as is the case with javascript.

If you want to run a php script when the user clicks a button without reloading the page, then you should study about AJAX.

    
26.03.2015 / 18:00
-1

The right thing would be for you to put something more complete than you already have and you're trying to do it, but I'll try to come up with an idea so you can try to implement, so you do not have to reload the page to decrease or change the value of your variable, any thing here post your difficulties.

Use ajax to send the value to a php page where there will be a variable that will receive this value and change the value of it according to your need, eg: in your javascript contained in your main page do

var url = "seuArquivo.php";
var data = "numjour="+valor;//Na variável "valor" vc pode atribuir um valor específico vindo do seu form por exemplo.
$.ajax({                 
        type: 'POST',                 
        //dataType: 'json',                 
        url: url,                 
        async: true,                 
        data: data,                 
        success: function(response) {
            $("#idSuaDiv").val(response);
            //Isso colocaria o resultado em sua div, mas vc pode fazer outras coisas aqui com a resposta
        }             
    });

In your .php file you would only need to get the value and do something with it or process it the way you want, eg:

 $beg_j = $_POST["numjour"];
    //agora faça o que vc quiser com a variável e depois mande a resposta de volta pro form.
print_r($beg_j);
    
03.11.2014 / 00:33