Hi

I am having an issue trying to run an sql query from a php script. I have checked the query through phpmyadmin and it runs fine but whenever I run it through php i get an error. The error is "Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given" I have seen lots of threads on this error and people commenting the error is caused my names not matching between the query and the db but I know this is not the case.

$result = mysql_query("SELECT name, company, email, active FROM members WHERE username='".$_POST['username']."' AND password=md5('".$_POST['pwd']."')");

$mem_details = mysql_fetch_array( $result );

I would really appreciate a fix to this if anyone can see it.

Thanks,

Ben

Member Avatar for LastMitch

@benclifford

The error is "Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given" I have seen lots of threads on this error and people commenting the error is caused my names not matching between the query and the db but I know this is not the case.

Take out the $_POST. Why do you need to put $_POST in your query?

Thanks for your reply LastMitch

This is for a login form so i was posting the username and password entered in this form to this script where it needs to do the authentication. I have taken the $_POST's out of the query string and placed the values into variables before the query so the code is as below, but i still get the same error.

$usr = $_POST['username'];
$pwd = $_POST['pwd'];

$result = mysql_query("SELECT name, company, email, active FROM members WHERE username='".$usr."' AND password=md5('".$pwd."')");
$mem_details = mysql_fetch_array( $result );
Member Avatar for LastMitch

I have taken the $_POST's out of the query string and placed the values into variables before the query so the code is as below, but i still get the same error.

I never seen md5 on a query like that.

Try to establish $md5:

$usr = $_POST['username'];
$pwd = $_POST['pwd'];
$md5 = $pwd;

From this:

$result = mysql_query("SELECT name, company, email, active FROM members WHERE username='".$usr."' AND password=md5('".$pwd."')");

To this:

$result = mysql_query("SELECT name, company, email, active FROM members WHERE username='$usr' AND password='$md5'");

or this:

$result = mysql_query("SELECT name, company, email, active FROM members WHERE username='$usr' AND password='md5($pwd)'");

What error you got if you ran the code? If you have any error.

Thanks, for your response. Sadly I have made a rookie mistake and the problem was nothing todo with the query but the usr making the connection through the php was not authorised on this sql db. with regards, to the md5 comment, I was trying to use the md5 function of mysql as oppose to the php one.

Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.