Update with PHP variable

Asked

Viewed 687 times

0

I’m taking a beating with a variable update. Please someone can help me?

$servidorBanco = "localhost";
$usuarioBanco = "root";
$senhaBanco = "";
$dadosBanco = "db";

$conexao = new mysqli($servidorBanco, $usuarioBanco, $senhaBanco, $dadosBanco);  

date_default_timezone_set('America/Sao_Paulo');
$hora = date('H:i:s');

$idHost = 1;

$consulta2 = $conexao->escape_string("UPDATE host SET uptimeHost='".$hora."', avisoHost=0 WHERE idHost='".$idHost);
$resultado4 = $conexao->query($consulta2);

Not updating in Mysql database.

  • Does what the iPramesPortas suggested, but first check if your SQL query is correct. Make a echo in SQL and test it in your database.

  • I’ve solved the problem, thank you.

3 answers

1


Ready I solved the resolution is that

$servidorBanco = "localhost";
$usuarioBanco = "root";
$senhaBanco = "";
$dadosBanco = "db";

$conexao = new mysqli($servidorBanco, $usuarioBanco, $senhaBanco, $dadosBanco);  

date_default_timezone_set('America/Sao_Paulo');
$hora = date('H:i:s');

$idHost = 1;

$sql = "UPDATE host SET uptimeHost='$hora', avisoHost=0 WHERE idHost='$idHost'";
if($conexao->query($sql) === true){
    echo "Atualizado com sucesso";
}else{
    echo "Não atualizado";
}

Thank you all.

0

$hora = date('H:i:s'); $idHost = 1;


$conexao = mysqli_connect("localhost","root","","banco");  

$sql = "update host set uptimeHost='$hora',avisoHost='0' where idHost='$idHost'"; 

$query = mysqli_query($conexao, $sql);
  • this connection already has. I will update the question.

0

Forgot to close the quotes

your code:

$consulta2 = $conexao->escape_string("UPDATE host SET uptimeHost='".$hora."', avisoHost=0 WHERE idHost='".$idHost);

as it should be:

$consulta2 = $conexao->escape_string("UPDATE host SET uptimeHost='$hora',avisoHost='0' WHERE idHost='$idHost');

Browser other questions tagged

You are not signed in. Login or sign up in order to post.