0
I have a system for borrowing a bag from an establishment I just wanted to be in control of who borrowed it from and what the bag number is, so I created a page where the numbers of the bags appear from 1 to 20 and when clicking the number 5 for example it redirects to another page of registration and already links or brings the number of the bag clicked in case the 5 ai just type the name phone and period and Cpf, when clicking send it adds to the bank the registration and changing the color of the button referring to bag 5 is in red, until then all right, now I can not do something to return this bag, I don’t want to delete from the bank just change the situation by clicking back on bag 5 I wanted her to change the situation of the bank and give the message back! Follows the codes.
create.php
<?php
session_start();
include_once 'conexao.php';
$nome = $_POST [ 'nome' ];
$telefone = $_POST [ 'telefone' ];
$cpf = $_POST [ 'cpf' ];
$sacola = $_POST [ 'sacola' ];
$periodo = $_POST [ 'periodo' ];
$queryInsert = $link->query("insert into tb_emprestimo VALUES(NULL,'".$nome."','".$telefone."','".$cpf."',".$sacola.",'".$periodo."',1)");
$affected_rows = mysqli_affected_rows($link);
if($affected_rows > 0):
$_SESSION['msg'] = "<p class='center green-text'>".'Empréstimo efetuado com Sucesso!'."<br>";
header("Location: ../sacola.php");
endif;
php connection.
<?php
$link = new mysqli('localhost','root','','db_sacola');
$link->set_charset('utf8');
if(!$link){
echo "Problemas ao realizar a conexao com o banco de dados (".mysql_error().")";
exit();
}
php bag.
<?php session_start();
include_once 'includes/header.inc.php';
include_once 'includes/menu.inc.php';
?>
<!-- Formulário de Cadastro Cliente -->
<div class="row container">
<p> </p>
<fieldset class="formulario" style="padding: 5px; width: 650px;">
<legend><img src="imagens/sacola.png" alt="[imagem]"style="width:50px; height:45px"></legend>
<br>
<?php
if(isset($_SESSION['msg'])):
echo $_SESSION['msg'];
session_unset();
endif;
?>
<?php
include_once 'banco_de_dados/conexao.php';
//if (!@include_once "conexao.php" ) {echo "Arquivo: conexao.php não incluso";};
$x = 1;
$sacola = 1;
while($x <= 4) {
echo "<div class='linha".$x."'>";
$y = 1;
while ($y <= 5) {
$sql = "SELECT SACOLA FROM TB_EMPRESTIMO WHERE SACOLA = ".$sacola." and SITUACAO = 1";
if($resultset = mysqli_fetch_assoc(mysqli_query($link, $sql))) {;
echo "<button id='botao' data-numero='".$sacola."' style='width:120px; height:37px; background-color: #A62A2A;'>".$sacola."</button>";
} else {
echo "<button id='botao' data-numero='".$sacola."' style='width:120px; height:37px; background-color: #4D4DFF;'>".$sacola."</button>";
}
$sacola = $sacola + 1;
$y = $y + 1;
}
$x = $x + 1;
}
?>
</fieldset>
</div>
<?php include_once 'includes/footer.inc.php';?>
<?php include_once 'includes/script.inc.php';
php loan.
<?php session_start();
include_once 'includes/header.inc.php';
include_once 'includes/menu.inc.php';
include_once 'banco_de_dados/conexao.php';
?>
<!-- Formulário de Cadastro Cliente -->
<div class="row container">
<p> </p>
<form action="banco_de_dados/create.php" method="POST" class="col s12">
<fieldset class="formulario" style="padding: 5px">
<legend><img src="imagens/sacola.png" alt="[imagem]"style="width:80px; height:45px"></legend>
<br>
<?php
if(isset($_SESSION['msg'])):
echo $_SESSION['msg'];
session_unset();
endif;
?>
<!-- Campo Nome -->
<div class="input-field col s12">
<i class="material-icons prefix">account_circle</i>
<input type="text" name="nome" id="nome" maxlength="40" required autofocus>
<label for="nome">Nome</label>
</div>
<!-- Campo Telefone -->
<div class="input-field col s12">
<i class="material-icons prefix">phone</i>
<input type="text" name="telefone" id="telefone" maxlength="13" required>
<label for="telefone">Telefone</label>
</div>
<!-- Campo Cpf -->
<div class="input-field col s12">
<i class="material-icons prefix">credit_card</i>
<input type="text" name="cpf" id="cpf" maxlength="14" required>
<label for="cpf"> CPF</label>
</div>
<!-- Campo Número da Sacola -->
<div class="input-field col s12">
<i class="material-icons prefix">local_mall</i>
<label>Numero da Sacola</label>
<input type="text" name="sacola" value="<?php echo isset($_GET['sacola']) ? $_GET['sacola'] : null;?>">
</div>
<!-- Campo Periodo -->
<div class="input-field col s12">
<i class="material-icons prefix">timelapse</i>
<select name="periodo">
<option value="" disabled selected>Período</option>
<option value="manha">Manhã</option>
<option value="tarde">Tarde</option>
<option value="noite">Noite</option>
</select>
</div>
<!-- Botões -->
<div class="input-field col s12">
<input type="submit"style="width:120px; height:37px" value="Empréstimo" class="btn blue">
<input type="submit"style="width:120px; height:37px" value="Devolução" class="btn red">
</div>
</fieldset>
</form>
</div>
<?php include_once 'includes/script.inc.php';
php script.
<!-- Arquivos Jquery e JavaScrip -->
<script type="text/javascript" src="materialize/js/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="materialize/js/materialize.min.js"></script>
<script type="text/javascript" src="materialize/js/jquery.mask.min"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.maskedinput/1.3.1/jquery.maskedinput.min.js"></script>
<!-- Inicialização Jquery -->
<script type="text/javascript">
$(document).ready(function(){
$('.sidenav').sidenav();
$('.dropdown-trigger').dropdown();
});
</script>
<!-- Inicialização Jquery Mascaras -->
<script type="text/javascript">
jQuery.noConflict();
jQuery(function($){
//$("#datanasc").mask("99/99/9999");
//$("#telefone").mask("(099)99999-9999");
$("#cpf").mask("999.999.999-99");
});
document.addEventListener('DOMContentLoaded', function() {
var elems = document.querySelectorAll('select');
var instances = M.FormSelect.init(elems, options);
});
// Or with jQuery
$(document).ready(function(){
$('select').formSelect();
});
</script>
<script>
//pega todos os botoes
const botoes = document.querySelectorAll('#botao');
for (let i = 0; i < botoes.length; i++) {
//escuta o evento de click em cada botao
botoes[i].addEventListener('click', function (e) {
//pega o numero do botao clicado
const sacola = this.dataset.numero;
//redireciona para emprestimos.php passando o numero do botao
window.location.href = `emprestimo.php?sacola=${sacola}`;
});
}
</script>
<!-- <script>
//muda cor do botão
function mudaCor(el){
var cor = el.style.backgroundColor;
if(cor == 'rgb(0, 0, 255)') {
el.style.backgroundColor = '#FF0000';
} else {
el.style.backgroundColor = '#0000FF';
}
}
</script> -->
</body>
</html>
At the time of you write your question some part of got no formatting, please edit for better view.
– Maury Developer
I don’t understand your quote I think you’re in trouble too!
– adriano eurich
I’m sorry for the Portuguese errors. There is in the question some part of the code that is not formatted with Highlight from php.
– Maury Developer
I don’t know why it doesn’t get inside the formatting some part!!
– adriano eurich
Thanks for the analysis, but I still do not understand why it was left without some formatting!
– adriano eurich