0
Good morning, you guys.
I have a page (index.php) that needs to return the database data to it. I have a . php (connection.php) that connects to the database, see:
$_SG['servidor'] = 'localhost'; // Servidor MySQL
$_SG['usuario'] = 'root'; // Usuário MySQL
$_SG['senha'] = 'XXXX'; // Senha MySQL
$_SG['banco'] = 'projetoqa'; // Banco de dados MySQL
$_SG['paginaLogin'] = '../login.php'; // Página de login
$_SG['tabela'] = 'usuarios'; // Nome da tabela onde os usuários são salvos
// ==============================
// ======================================
// ~ Não edite a partir deste ponto ~
// ======================================
// Verifica se precisa fazer a conexão com o MySQL
if ($_SG['conectaServidor'] == true) {
$_SG['link'] = mysql_connect($_SG['servidor'], $_SG['usuario'], $_SG['senha']) or die("MySQL: Não foi possível conectar-se ao servidor [".$_SG['servidor']."].");
mysql_select_db($_SG['banco'], $_SG['link']) or die("MySQL: Não foi possível conectar-se ao banco de dados [".$_SG['banco']."].");
}
// Verifica se precisa iniciar a sessão
if ($_SG['abreSessao'] == true)
session_start();
The connection I know is OK, because I already used another function of the code to insert content in it. However, on the index.php page where I need to display results, I can’t. See the code:
<?php
// Inclui o arquivo com o sistema de segurança
require_once("php/conexao.php");
// executa a query
$busca = "SELECT titulo FROM questoes";
$resultado = mysql_query($busca);
// Encerra a conexão
mysql_close();
?>
And where the result should be displayed:
<li><a href="#"><?php $resultado ?></a></li>
Just stay blank! Nothing shows up. What’s wrong with this case? I looked at some forums and other methods of how to perform the search, I couldn’t find it. The data in question that returns there, is just a title. For example "How to play video game?"
Thank you!
OMG
Buddy, I get a few headaches just trying to read your code, because you’ve defined the Arrays in a somewhat laborious way, even though the technique is outdated, inefficient, and not recommended, you’ve made it even more complicated. Try putting aecho $resultado
, I need to take a closer look at your code.– Edilson
I will try. Sorry for the disorganization of the code, really not only new in PHP and SQL, I’m still just messing with the code without organizing it yet.
– Rodrigo BRF
Try a var_dump($result) to see what is being returned in the variable and a hint, the mysql_* functions are deprecated from php 5.5, try replacing with PDO or mysqli_*.
– user28595