For that you’d have to use ajax, using pure javascript or else jquery, and attach an event scavenger to that div. However, I don’t see much point in doing this with a div, and even more so in this way.
In this example I will use jquery because I don’t have the best conditions at my disposal.
$(document).ready(function(){
// mouseover, mouseout, leave
$("#click").on('click', function(){
var rando = 1 + Math.floor(Math.random() * 100); // gerar numeros entre 1 e 100
$.post('upd.php',{status: rando}, function(i){
$("#demo").html('Retorno: ' + i);
});
});
});
This is the part of jquery, I used the event click to avoid complications, and it’s also a little awkward to process requests whenever the mouse passes over a div, which will probably happen all the time. I commented on the upcoming events.
We in requisitions with the ajax you can always choose between $.post, $.get, or even $.ajax.
- $.post and $.get (without much configuration);
- $.ajax (more configuration options, both for get as post).
To the html you’d have something like that:
<div id="demo"></div>
<div id="click"></div>
And this to dispose the Divs one above the other:
<style type="text/css">
div {display:block;}
#click {width:100%; height:20px; background-color:#204a87; content:"OI";}
</style>
And finally, for the script php you could do something like this:
session_start();
$data = isset($_POST['status']) && !empty($_POST['status']) ? (int) $_POST['status'] : "indefinido\n";
// Restantes verificações para $data...
if(isset($_SESSION['status']) && !empty($_SESSION['status'])){
echo $_SESSION['status'];
} else {
$_SESSION['status'] = $data;
echo $_SESSION['status'];
}
session_destroy();
In this example I used sessions to illustrate how the exchange of values of this same variable would be, for the case of status be different with each request. For a query where you have the treatment of session variables you would put the query SQL, being like this:
$status = isset($_POST['status']) && !empty($_POST['status']) ? (int) $_POST['status'] : "indefinido";
// Restantes verificações para $status...
db::Query("UPDATE bdc SET status='{$status}'");
Edit with the code you already made
– Giancarlo Abel Giulian
I only have the function to insert in the bank.
– Josimara
I created an imput with an onclick, but then the ajax function I couldn’t do
– Josimara
You need to do javascript, detect the click on the div and trigger ajax to update the values with php.
– rray
I’ve got it all figured out.
– Josimara