2
I cannot list a simple table in php... I don’t see what’s wrong with the code, when I run this php code just shows me a blank page... What I’m doing wrong?
<html>
<head>
<title>Listar Alunos</alunos>
</head>
<body>
<?php
//Conecta ao servidor e escolhe a base de dados
mysql_connect("localhost", "root", "");
mysql_select_db("login");
$query = "SELECT * FROM alunos";
if ($resposta = mysql_query($query)){
echo
'
<table align = "left" cellspacing = "5" cellpadding = "8">
<tr><th align = "left"><b>Primeiro Nome</b></th>
<th align = "left"><b>Último Nome</b></th>
<th align = "left"><b>Email</b></th>
<th align = "left"><b>Rua</b></th>
<th align = "left"><b>Cidade</b></th>
<th align = "left"><b>Telemóvel</b></th>
<th align = "left"><b>Data de Nascimento</b></th>
<th align = "left"><b>Sexo</b></th><tr>
';
while($row = mysql_fetch_array($resposta)){
echo '<tr><td align = "left">' .
$row['primeiro_nome'] . '</td><td align = "left">' .
$row['ultimo_nome'] . '</td><td align = "left">' .
$row['email'] . '</td><td align = "left">' .
$row['rua'] . '</td><td align = "left">' .
$row['cidade'] . '</td><td align = "left">' .
$row['telemovel'] . '</td><td align = "left">' .
$row['data_aniversario'] . '</td><td align = "left">' .
$row['sexo'] . '</td>' ;
echo '</tr>';
}
echo '</table>';
} else{
echo "Não foi possível listar os alunos. ".mysql_error();
}
?>
</body>
mysql is obsolete, use mysqli or Pdo
– Sveen
is for a school project... Since I can’t touch the machines there, unfortunately I have to use in php 5 version... Think the problem may be from there?
– j. doe
You are testing locally, or on the school server?
– Sveen
This file has that extension?
– Felipe
locally, with the shaman
– j. doe
is called listing.php
– j. doe
Share this listing code.php.
– Mike Otharan