mySQL query problem

Hi guys. Just wonder what’s wrong with this code:

$collect_codes = func_query(“SELECT value FROM dcodes”);

That would depend on what programming language this is and what your mySQL database structure looks like and what kind of error message (if any) you are receiving.

I use PHP 5. Database has table dcodes and row value.

What is func_query?

Shouldn’t you be using

$result = mysql_query('SELECT value FROM dcodes');

Value should be a valid name of a column, and dcodes should be a valid name of a table.

1 Like

I used mysql_query, So now it runs but the new problem is that it doesn’t collect anything(but database has a value)

Try this to see if there is anything at all in the table you are referring to:
$result = mysql_query("SELECT * FROM dcodes");

That will return the entire table. If your connection is established.
It will not have the field names (col headers) though.
Are you sure you have a column (field name) simply called value?


Yes, it has a column value with some numbers on the dcodes table

I did this before with other tables and it was good and now nothing. Maybe I need to connect the database somehow again?

That could be it.
Sometimes you need to logon to the server to access folders or databases.
If it is pulling nothing the connection could be the problem.

No errors?

You could try and connect to the data in another way, like scripting excel VBA, it will certainly throw an error if you can’t connect.


Please take note of the message here -
That is depcreated already and you need to use Myqli or PDO

what’s wrong with this:

$result = mysql_query("SELECT * FROM dcodes");
	if ($result) {
    echo 'hi';

	echo 'bye';

I have table dcodes and it returns nothing and echoing ‘bye’.
What’s the problem?

1 Like

Because the condetion not completed

What i mean is “deprecated” :smiley:, its just a typo. Its meant that it is already obsolete and wont be used anymore in the future php version.

Also that line, it will always be true, because its just evaluating whether the query you made is correct or not.
You need to use - mysql_fetch_row to count the number of rows or simply get the result via mysql-fetch-assoc.php

Enjoy coding.

I need to rephrase my answer. You said earlier that your php version is 5 and you didnt mentioned which specific version because this command mysql_query is already in php 5.5.0 deprecated.

I think this lines always results to nothing and just display the ‘bye’ because of that reason that its deprecated - in case your php version is php 5.5.0 up! :smiley:

My reason above, its just deprecated and wont be used anymore in php5.5.0 and higher.