2
I’m an amateur programmer and I’m having a problem printing an eco php inside a div.
I have a file that when accessed (only once) will start the database installation:
mysqli_report(MYSQLI_REPORT_STRICT);
try
{
$mysqli = new mysqli("localhost","root","");
$mysqli->query("CREATE DATABASE IF NOT EXISTS respostas;");
$ok = "Banco de dados criado com sucesso...";
}
catch (Exception $e)
{
$error = "Desculpe alguma coisa não deu certo. Detalhes: " . $e->message;
}
And display the result in <div id="progress">
$pageBody = <<< EOPAGE
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html>
<html lang="pt-br">
<head>
<title>Home | Configuração </title>
<meta http-equiv="Content-Type" content="txt/html; charset=utf-8" />
</head>
<body>
<div class="body">
<div class="text">
<p><h1>Bem Vindo</h1></p>
<br/>
<br/>
<p class="texts"><i class="fa fa-cog"></i>Iniciaremos agora as configurações finais. Aguarde enquanto todos os arquivos são configurados.</p>
<div id="progress">
<p>Aguardando</p>
<p>$ok</p>
<p>$error</p>
</div>
</div>
</div>
</body>
</html>
EOPAGE;
echo $pageBody;
However, when I call $ok
the message is displayed normally, but when I call the $erro
does not display error message, even simulated an error connection to the server, and the code gives error.
Put like this and test <?php echo $ok; ? > and <?php echo $error; ? > say something
– César Sousa
@Césarsousa, unfortunately does not display the message. And when I put both,
<?php echo $ok;?>
and<?php echo $error
>, returns an error message.– Jamil Filho
the correct would not be $e->getMessage ?
– Isvaldo Fernandes
@Isvaldofernandes, tried using getMessage, however, did not work. Even leaving only the <p>$error</p> and simulating a connection failure, it does not return the message, but the code error.
– Jamil Filho