Saving your code number in a database using PHP:
You can use an AJAX request to access a PHP page and save the variable to the data bank as implemented in your code:
<!DOCTYPE html>
<html>
<head>
<title>Contador</title>
<link rel="stylesheet" href="css/bootstrap.min.css">
<script src="js/bootstrap.min.js"></script>
<script type="text/javascript">
var Cont1 = 0;
function balcao1(){
Cont1 = Cont1 + 1;
document.getElementById('contador1').value = Cont1;
//AQUI A REQUISIÇÃO AJAX
$.ajax({
//pode ser post ou get
type: "GET",
//url aonde a pagina php responsavel por salvar no banco está.
url: "registra_banco.php?valor=Cont1",
//você está passando o valor de Cont1 via get para a pagina registra_banco.php
cache: false,
success: function (retorno) {
alert("salvo no banco de dados!);
},
error: function(retorno) {
alert("erro!);
}
});
}
</script>
<style type="text/css">
#contador1{
font:bold 150px Arial;
padding: 50px;
color:#FF0000;
border:2px dashed #f1f1f1;
width:350px;
height:350px;
text-align:center;
line-height: 200px;
}
.btn{
margin-top: 20px;
margin-left:130px;
}
</style>
</head>
<body>
<div class="col-md-3">
<center><h1><span class="label label-default">Senha A </span></h1></center>
<input id="contador1"><br>
<input type="button" class="btn btn-success" value="Próximo" onclick="balcao1();">
</div>
</body>
</html>
Well remember that ajax is from jquery library. it is sending the value to the registra_database.php page via get (by url) and so later be saved in the database
Example of what the registra_bank.php page would look like.:
<?php
//abre uma conexão com o banco de dados, esses parametros variam de como foi feito seu banco de dados
$conn = new PDO("mysql:host=localhost;dbname=data_dashboard", "root", "" );
//pega o valor passado via ajax e atribui a uma variavel
if (isset($_GET['valor'])) {
$valor= $_GET['valor'];
}
//agora que você tem o valor você precisa dar um insert no seu banco de dados
//monta a query que será executada no banco (depende de como está sua tabela tambem)
$query = "insert into valores values('$valor')";
//rode o metodo de executar a sua query no banco
$db->execute($query);
?>
If on your screen appears the saved Alert, it is because the ajax request worked, if it gives error, it is because the ajax request failed
Remembering that there are countless ways to do this, in this method
were used POO and AJAX., to deepen into the connection class with
the php database :
http://php.net/manual/en/class.pdo.php
and to ajax recommend:
http://www.devfuria.com.br/javascript/ajax-php-jquery/
not understood very well, you want that when the number appears in the "screen" it is written in the database?
– Julio Henrique
What do you know about programming language and database? What language are you using, or do you want? The same question for the database.
– KaduAmaral
it’s like this yes ... I’ll be more specific ... I’m not very good in php to write the data in the BD ... but it’s like when we fill out a form and click SEND and the data is in the BD because it’s the same idea I want here that when I click the PROXIMO button that the #1 gets recorded , then when you click again that the number 2 is recorded and so on ... please help me
– Onurb Bruno
Kaduamaral ... I know more about html and css and a bit of database when it comes to database searches but when it comes to php I don’t really know anything ... and how to record numbers in the database you need php so I’m here asking for your help ... thank you
– Onurb Bruno
@Uchihabruno posted the answer
– Julio Henrique
@Juliohenrique97 thank you very much for the help I will do everything if you can send me your facebook to talk better I would thank you very much , because no one has ever helped me as well as you directly , since I am new here in the stack , hug
– Onurb Bruno
@Uchihabruno blz , You have to ask the question then
– Julio Henrique