Update with PHP variable [closed]

0

I'm taking a beating with an update with variable. Please, can anyone 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.

    
asked by anonymous 26.02.2018 / 23:52

3 answers

0

Ready I solved the resolution is this

$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.

    
27.02.2018 / 01:08
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);
    
27.02.2018 / 00:19
0

You forgot the dates in quotation marks

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');
    
27.02.2018 / 00:32