-1
I’m having a problem getting information from a database, the code I tried was this:
require_once "config.php"; // database
$sql = mysql_query("SELECT conteudo FROM home NULL NULL NULL") or die("MySQL error:".mysql_error());
$result = mysql_fetch_array($sql);
echo $result;
Only nothing happens, there’s no information that I got from the database, no idea what’s going on?
NOTE: If there is an error on the page, here is the code:
<html>
<head>
<title>Trilhas da Terra</title>
<link rel="stylesheet" type="text/css" href="style.css">
<meta charset="UTF-8">
</head>
<body>
<div id="menu">
<ul class="main">
<li><a class="item" href="index.html"><div>Home</div></a></li>
<li><a class="item" href="quem.html"><div>Quem Somos</div></a></li>
<li><a class="item" href="roteiros.html"><div>Roteiros</div></a></li>
<li><a class="item" href="portfolio.html"><div>Portfolio</div></a></li>
<li><a class="item" href="contato.html"><div>Contato</div></a></li>
<li style="float:right;"><a class="item" href="login.html"><div>Admin</div></a></li>
</ul>
</div>
<div id="logo"><img src="imagens/logo.jpg"></div>
<div id="info">
<div id="wtitle">Home</div>
<br>
<div id="wcont">
<?php
require_once "config.php"; // database
$sql = mysql_query("SELECT conteudo FROM home NULL NULL NULL") or die("MySQL error:".mysql_error());
$result = mysql_fetch_array($sql);
echo $result;
?>
</div>
</div>
<div id="widside">
<div id="wtitle">Trilhas do Barro Serra do Mar</div>
</div>
<script src="some.js"></script>
</body>
</html>
That one
NULL NULL NULL
is very suspicious, already tried to take it out of the query?– bfavaretto
Yes, nothing’s changed, NULL’s are for WHERE ORDER and LIMIT
– Junior CT
But I think these Nulls give syntax error. And there is no error? If you give a
var_dump($result)
, what appears?– bfavaretto
It did not appear anything, I was surprised, so I put only an echo and a text, it did not appear, it seems that is some error in the placement of the code, I will edit the question and paste the code of the page
– Junior CT
All right, see if you can find anything wrong.
– Junior CT
Put this at the beginning of your PHP code, above the
require_once
:error_reporting(E_ALL);
ini_set('display_errors', 1);
– bfavaretto
Okay, it appeared that it was a syntax error because of NULL so I took them out, now nothing came up, not the content of the comic or any error.
– Junior CT
Tried the
var_dump
?– bfavaretto
returned: Boolean false
– Junior CT
This means that there is an error in the execution of the query. It may be a problem connecting to the bank (make sure everything is all right in the file being included). It can also be an error in the table or column name in your select. Something else: you should no longer use the functions
mysql_
, they are being discontinued. Usemysqli
or PDO (read the warning in red here).– bfavaretto
This SQL sentence: "SELECT conteudo FROM home NULL NULL NULL" is syntactically wrong. See: http://dev.mysql.com/doc/refman/5.7/en/select.html
– user4552
possible duplicate of mysql_query returning false
– mgibsonbr