-3
Hello, I have a problem in my code that I did not find the problem.
When trying to edit the ID 1750 it runs but saved in ID 0, I wonder if my code has any error in this sense, why by clicking edit on the line I want it accesses and pulls data from it but when I try to save it always goes in ID 0.
Error showing
Warning: Trying to access array offset on value of type null in C: xampp htdocs eletrictel panel projects_edit.php online 244
// Classe Projeto Editar.php
<?php
include('../class/classe_verifica_login.php');
include_once('../class/classe_conexao.php');
$id = filter_input(INPUT_GET, "id", FILTER_SANITIZE_NUMBER_INT);
$result_empresa = "SELECT * FROM empresa WHERE id='$id' LIMIT 1";
$resultado_empresa = mysqli_query($conexao, $result_empresa);
$row_empresa = mysqli_fetch_assoc($resultado_empresa);
?>
<form method="POST" action="projeto_editar.php">
<div class="row">
<div class="col-md-5">
<div class="form-group">
<label class="bmd-label-floating">ID ( Desabilitado )</label>
//linha 244 <input type="text" name="id" id="id" class="form-control" value="<?php echo $row_empresa['id']; ?>" disabled>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label class="bmd-label-floating">Empresa</label>
<input name="nm_empresa" type="text" value="<?php echo $row_empresa['nm_empresa']; ?>" class="form-control">
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label class="bmd-label-floating">Status</label>
<input name="pj_status" type="text" value="<?php echo $row_empresa['pj_status']; ?>" class="form-control">
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label class="bmd-label-floating">Nome do projeto</label>
<input name="nm_projeto" type="text" value="<?php echo $row_empresa['nm_projeto']; ?>" class="form-control">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label class="bmd-label-floating">Número de EI</label>
<input name="nm_ei" type="text" value="<?php echo $row_empresa['nm_ei']; ?>" class="form-control">
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label class="bmd-label-floating">Nome da concessionária</label>
<input name="nm_concessionaria" type="text" value="<?php echo $row_empresa['nm_concessionaria']; ?>" class="form-control">
</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label class="bmd-label-floating">Cidade</label>
<input name="nm_cidade" type="text" value="<?php echo $row_empresa['nm_cidade']; ?>" class="form-control">
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label class="bmd-label-floating">Kilometragem</label>
<input name="qnt_kilometragem" type="text" value="<?php echo $row_empresa['qnt_kilometragem']; ?>" class="form-control">
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label class="bmd-label-floating">Quantidade de postes</label>
<input name="qnt_postes" type="text" value="<?php echo $row_empresa['qnt_postes']; ?>" class="form-control">
</div>
</div>
<!--
<div class="col-md-4">
<div class="form-group">
<label for="cadastro" class="bmd-label-floating">Cadastro</label>
<input name="cadastro" type="text" class="form-control">
</div>
</div>
-->
</div>
<button type="submit" class="btn btn-primary pull-right">Atualizar</button>
```
```
// Classe Projeto Editar.php
<?php
include('../class/classe_verifica_login.php');
include_once('../class/classe_conexao.php');
$id = filter_input(INPUT_POST, "id", FILTER_SANITIZE_NUMBER_INT);
$nm_empresa = filter_input(INPUT_POST, 'nm_empresa', FILTER_SANITIZE_STRING);
$pj_status = filter_input(INPUT_POST, 'pj_status', FILTER_SANITIZE_STRING);
$nm_projeto = filter_input(INPUT_POST, 'nm_projeto', FILTER_SANITIZE_STRING);
$nm_ei = filter_input(INPUT_POST, 'nm_ei', FILTER_SANITIZE_STRING);
$nm_concessionaria = filter_input(INPUT_POST, 'nm_concessionaria', FILTER_SANITIZE_STRING);
$nm_cidade = filter_input(INPUT_POST, 'nm_cidade', FILTER_SANITIZE_STRING);
$qnt_kilometragem = filter_input(INPUT_POST, 'qnt_kilometragem', FILTER_SANITIZE_STRING);
$qnt_postes = filter_input(INPUT_POST, 'qnt_postes', FILTER_SANITIZE_STRING);
$conexao->query("UPDATE empresa SET
nm_empresa = '$nm_empresa',
pj_status = '$pj_status',
nm_projeto = '$nm_projeto',
nm_projeto = '$nm_projeto',
nm_ei = '$nm_ei',
nm_concessionaria = '$nm_concessionaria',
nm_cidade = '$nm_cidade',
qnt_kilometragem = '$qnt_kilometragem',
qnt_postes = '$qnt_postes',
modificado = NOW()
WHERE users.id = $id");
if(mysqli_affected_rows($conexao)) {
$_SESSION['sucesso'] = true;
header("Location: projetos_editar.php?id=$id");
} else {
$_SESSION['negado'] = true;
header("Location: projetos_editar.php?id=$id");
}
?>
```
I couldn’t reproduce the error. I removed includes because I have no way to replicate them, I removed the part of the database because I have no way to replicate, enabled the input and what was passed through the request post arrives unchanged.
– Augusto Vasques