Error while collecting database information

Asked

Viewed 146 times

-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?

  • Yes, nothing’s changed, NULL’s are for WHERE ORDER and LIMIT

  • But I think these Nulls give syntax error. And there is no error? If you give a var_dump($result), what appears?

  • 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

  • All right, see if you can find anything wrong.

  • Put this at the beginning of your PHP code, above the require_once: error_reporting(E_ALL);&#xA;ini_set('display_errors', 1);

  • 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.

  • Tried the var_dump?

  • returned: Boolean false

  • 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. Use mysqli or PDO (read the warning in red here).

  • 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

  • possible duplicate of mysql_query returning false

Show 7 more comments

1 answer

2

If you do not want to create any clause for your query, just do not type anything, the NULLS which you have added are displaying syntax error. Leave your query as follows mysql_query("SELECT conteudo FROM home") that should work.

Always remember that: 'content' refers to COLUMN, while 'home' is the TABLE of the database and not the name of the database itself. You must have made some confusion regarding these concepts. If you do not succeed, make sure that the file config.php is successfully making the connection and that the column and table name have been entered correctly.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.