0
Staff I am having difficulty updating my database to decrease the weight by 1 kg. Any help I appreciate. The code is as follows:
<?php
class Aluno{
public $nome;
public $endereco;
public $peso;
public $altura;
function __construct($nome, $endereco, $peso, $altura, $imc, $programa) {
$this->nome = $nome;
$this->endereco = $endereco;
$this->peso = $peso;
$this->altura = $altura;
$this->imc = $imc;
$this->programa = $programa;
$this->imc = $this->calcularIMC();
$this->peso = $this->calcularPeso();
if ($this->imc<17) {$this->programa = "de ganho de peso.";
}
elseif ($this->imc>30) {$this->programa = "de perda de peso.";
}
else {$this->programa = "de manutenção do peso.";
}
}
function calcularPeso() {return round(($this->peso - 1),2);}
function calcularIMC() {return round(($this->peso)/($this->altura*$this->altura),2);}
}
$conexao = mysqli_connect("localhost", "root", "", "academia");
if(mysqli_connect_errno($conexao))
{
echo "Não conectado!<br>";
}
else {
mysqli_query($conexao, "SET NAMES 'utf8'");
echo "Conectado!</br></br>";
}
$listagem = mysqli_query($conexao, "SELECT * FROM aluno");
while ($linha = mysqli_fetch_array($listagem)) {
$alunoTemp = new Aluno($linha['nome'], $linha['endereco'], $linha['peso'], $linha['altura'], $linha['imc'], $linha['programa']);
$sql = mysqli_query($conexao, "UPDATE aluno SET peso = peso WHERE nome=nome");
}
?>
The difficulty is an error or unexpected result? could describe better.
– rray
If you’re making a mistake, edit your question and add this information.
– emanuelsn
Do you want to pass the values of the student object in the update? pass the respective properties, use simple quotes for text field values, or use Prepared statements.
– rray
change weight = weight by weight = {$alunoTemp->weight} and do the same in Where, and if I were you would update by id instead of name
– Adir Kuhn