-1
I’m getting this error while accessing the page:
You have an error in your SQL syntax; check the manual that Corresponds to your Mysql server version for the right syntax to use near '' at line 1
<html>
<head>
<title>Extraindo dados de um BD</title>
</head>
<body>
<dl>
<?php
//Conectando com o BD...
mysql_connect($host,$username,$pass) or die(mysql_error());
//Selecionando o BD...
mysql_select_db($db_name) or die(mysql_error());
// Extrair dados de acordo com o id passado no URL
$strSQL = "SELECT * FROM People WHERE id=" . $_GET["id"];
$rs = mysql_query($strSQL) or die(mysql_error());
// Loop pelo recordset $rs
while($row = mysql_fetch_array($rs)) {
// Escreve dados da pessoa
echo "<dt>Nome:</dt><dd>" . $row["FirstName"] . " " . $row["LastName"] . "</dd>";
echo "<dt>Telefone:</dt><dd>" . $row["Phone"] . "</dd>";
echo "<dt>Data de nascimento:</dt><dd>" . $row["BirthDate"] . "</dd>";
}
//Encerra a conexão
mysql_close();
?>
</dl>
<p><a href="list.php">Go back to name's list</a></p>
and the other code is:
<html>
<head>
<title>Extraindo dados de um BD</title>
</head>
<body>
<?php
//Catalogo de enderecos simples
//Conectando com o BD...
mysql_connect($host,$username,$pass) or die(mysql_error());
//Selecionando o BD...
mysql_select_db($db_name) or die(mysql_error());
//Digitando a query SQL...
$strSQL = "SELECT * FROM People ORDER BY FirstName DESC";
//Executando a query e colocando seu resultado num Record Set, no caso $rs:
$rs = mysql_query($strSQL);
//Fazendo um loop pelo Record Set:
while ($row = mysql_fetch_array($rs)) {
//Nome da pessoa
$strName = $row['FirstName'] . " " . $row['LastName'];
// Cria link para o arquivo person.php com um valor de id no URL
$strLink = "<a href = 'person.php?id = " . $row['id'] . "'>" . $strName . "</a>";
// Lista de links
echo "<li>" . $strLink . "</li>";
}
mysql_close();
?>
See if $_GET['id'] is not empty
– rray
You are declaring the variables, host, username, pass right? Just removed them from there?!
– João Neto