AphexBeirut
AphexBeirut

Reputation: 29

mysql_query() expects parameter 1 to be string, resource given

My code is this:

$query = mysql_query("SELECT * FROM tb_funcionario");

$result = mysql_query($query);

And it's always giving me the

mysql_query() expects parameter 1 to be string, resource given

How can I solve it?

Upvotes: 3

Views: 53963

Answers (6)

Yann Boisclair-Roy
Yann Boisclair-Roy

Reputation: 179

Your problem comes from those lines:

$query = mysql_query("SELECT * FROM tb_funcionario");

$result = mysql_query($query);

Your calling the mysql_query() function twice.

You can do:

$sql = "SELECT * FROM tb_funcionario";

$result = mysql_query($sql);

Or either:

$result = mysql_query( "SELECT * FROM tb_funcionario" );

Upvotes: 1

Nobita
Nobita

Reputation: 23713

Look at this:

$query = mysql_query("SELECT * FROM tb_funcionario");
$result = mysql_query($query);

Change it for:

$query = "SELECT * FROM tb_funcionario");
$result = mysql_query($query);

Upvotes: 1

jere
jere

Reputation: 4304

your problem is here $query = mysql_query("SELECT * FROM tb_funcionario");

then you are running mysql_query($query) and it's trying to run the command against the resultset returned by the first statement, not a string like it should actually be

Upvotes: 2

WWW
WWW

Reputation: 9860

$query = mysql_query("SELECT * FROM tb_funcionario");
$result = mysql_query($query);

Is incorrect. You should just be assigning the query string to $query - what you're doing is running the query once, then trying to run the result of the query as a query again. You should have:

$query = "SELECT * FROM tb_funcionario";
$result = mysql_query($query);

which would give you the results you seek.

Upvotes: 2

miku
miku

Reputation: 188064

You have some unnecessary/wrong lines in your code:

$query = mysql_query("SELECT * FROM tb_funcionario");

$result = mysql_query($query);

I guess you wanted to write:

$query = "SELECT * FROM tb_funcionario";

$result = mysql_query($query);

Upvotes: 3

David
David

Reputation: 218877

You're running a query on the first line, which returns a "resource" as a result of the query. Then on the immediate next line you try to use that resource as another query to run again. You don't need the second line, the $result can be set in the first line.

Upvotes: 6

Related Questions