Rectangle 27 38

Your query ($myQuery) is failing and therefore not producing a query resource, but instead producing FALSE.

To reveal what your dynamically generated query looks like and reveal the errors, try this:

$result2 = mysql_query($myQuery) or die($myQuery."<br/><br/>".mysql_error());

The error message will guide you to the solution, which from your comment below is related to using ORDER BY on a field that doesn't exist in the table you're SELECTing from.

The error it gives is: Unknown column 'id' in 'order clause'

error is bellow that line... look echo & str_replace() bellow.

Then your 'residential' table doesn't have a field called id so you can't order by it. Take that out or order by a field that you have and the query will run :-)

One last problem, now it shows: Resource id #4. What does this mean?

php - Warning: mysql_fetch_array() expects parameter 1 to be resource,...

php mysql
Rectangle 27 38

Your query ($myQuery) is failing and therefore not producing a query resource, but instead producing FALSE.

To reveal what your dynamically generated query looks like and reveal the errors, try this:

$result2 = mysql_query($myQuery) or die($myQuery."<br/><br/>".mysql_error());

The error message will guide you to the solution, which from your comment below is related to using ORDER BY on a field that doesn't exist in the table you're SELECTing from.

The error it gives is: Unknown column 'id' in 'order clause'

error is bellow that line... look echo & str_replace() bellow.

Then your 'residential' table doesn't have a field called id so you can't order by it. Take that out or order by a field that you have and the query will run :-)

One last problem, now it shows: Resource id #4. What does this mean?

php - Warning: mysql_fetch_array() expects parameter 1 to be resource,...

php mysql
Rectangle 27 1

mysql_fetch_array() expects parameter 1 to be resource boolean given in php error on server if you get this error : please select all privileges on your server. u will get the answer..

php - Warning: mysql_fetch_array() expects parameter 1 to be resource,...

php mysql
Rectangle 27 1

mysql_fetch_array() expects parameter 1 to be resource boolean given in php error on server if you get this error : please select all privileges on your server. u will get the answer..

php - Warning: mysql_fetch_array() expects parameter 1 to be resource,...

php mysql
Rectangle 27 16

The mysql_query is returning a boolean value meaning the sql query is probably failing and you're getting a false returned rather than a mysql resource.

My problem is that the query is working when I perform it for one single field, though it returns me a boolean result and therefore False if I perform the search on 2 fields.

php - mysql_num_rows() expects parameter 1 to be resource, boolean giv...

php
Rectangle 27 3

You have an error in your query (forgot the and). Try this

SELECT * FROM category WHERE tier='2' and parent='$p_id' ORDER BY id ASC

php - How to fix Warning: mysql_fetch_array() expects parameter 1 to b...

php sql
Rectangle 27 3

This means mysql_query failed to execute the query, and you should use mysql_error() to see the error message.

$sql_1=mysql_query("SELECT * FROM category WHERE tier='2' AND parent='$p_id' ORDER BY id ASC");

+1 ... and not PDO yet, PDO is not good for beginners. He must learn some mysql basics first :)

thanks for the link i'll go and check it out

php - How to fix Warning: mysql_fetch_array() expects parameter 1 to b...

php sql
Rectangle 27 2

You've got an SQL syntax error:

$sql_1=mysql_query("SELECT * FROM category WHERE tier='2' parent='$p_id' ORDER BY id ASC");
                                                         ^-- missing ' AND '

If you had proper error handling in your code, you've have seen this:

$sql_1 = mysql_query(...) or trigger_error(mysql_error());
                         ^^^^^^^^^^^^^^^^^^^^^^--- bare mininum handling

Thanks for the quick responce. I am new to all this and i lack a lot of knowledge, i will try to keep that in my mind

php - How to fix Warning: mysql_fetch_array() expects parameter 1 to b...

php sql
Rectangle 27 4

$result = mysql_query($query) or die(mysql_error());

As per the billions of other answers on this site, the mysql functions return a boolean FALSE when things fail, which you're not checking for. Even if the query string is syntactically perfect, there's literally hundreds of other reasons why the query might still fail. Blindly assuming success is a very bad thing to do.

You're doing a WHERE somevalue = (subquery). For that kind of comparison, the subquery can return only a single row/value. You'd have to conver to a WHERE somevalue IN (subquery), which allows for multiple rows.

php - ERROR > WARNING : Warning: mysql_fetch_array() expects parameter...

php mysql warnings
Rectangle 27 4

$amn = mysql_query("SELECT * FROM `Messages` WHERE to_user='$usr' AND read='0'");

if($amn === false) {
    var_dump(mysql_error());
}
else {
    print_r(mysql_num_rows($amn));
}

Code above is written in bad style and deprecated. Use PDO with Exceptions in real projects.

php - Warning: mysql_num_rows() expects parameter 1 to be resource, bo...

php mysql
Rectangle 27 1

mysql_query

indeed, so it's handy to build an or die after it if the query fails. Thus because it can break your whole page mayby if it's fails....

die() should never be used in production code. But maybe an "or throw exception" in a try...catch block.

why not? if it's break the whole page, you can use the die to generate the error and mail it to you, and include an error page. So the user sees the error page, and the programmer / owner of the website get's an email with the error, and then can he have a look at the error and fix it...

die() stops all execution of code, possibly rendering half-outputted html which is messy. In addition, die(mysql_error($link)) is common, and this is possibly the worst practise that can be used. It shows the error to the user.

that's why you have to generate the HTML at the end, and send the mysql error trought an email to the owner of the website (or programmer). And then include an error page. Or rederict to the error page, so nothing else will be shown.....

php - mysql_fetch_array() expects parameter 1 to be resource, boolean ...

php mysql select pagination
Rectangle 27 1

copy and paste your query

select * from portalmakale where id='$id'

directly in database there it will show you the error.

also you can use mysql_error()like this

$sorgu=mysql_query("select * from portalmakale where id='$id'") or mysql_error();

php - Warning: mysql_fetch_array() expects parameter 1 to be resource,...

php mysql while-loop row
Rectangle 27 1

This means that there was an error while executing the query, or no result set was returned, and therefore the result is a boolean. This is causing the warning.

Check the value of $filterres before you enter this code segment, to get rid of the warning.

php - Warning: mysql_fetch_array() expects parameter 1 to be resource,...

php mysql
Rectangle 27 2

To ensure that the while only executes when the query succeeded you could write:

if ($query)
while($res = mysql_fetch_assoc($query)) {
    mysql_query("UPDATE products SET publicado = '0' WHERE auto_pub = ".$hoje) or die(mysql_error());
}

Notice the absence of the $query= assignment within the loop. For an UPDATE you don't want to read any results. And you are checking the outcoume with the or die already anyway.

php - How to fix this error "mysql_fetch_assoc() expects parameter 1 t...

php mysql
Rectangle 27 2

$query is used before the while and inside the while... Change the name of the variable to $query2, for example:

$hoje = strtotime(date("d-m-Y"));

$db = new DBConfig();
$db -> config();
$db->conn();
$query = mysql_query("SELECT * FROM products WHERE auto_pub = ".$hoje) or die(mysql_error());

while($res = mysql_fetch_assoc($query)) {
    $query2 = mysql_query("UPDATE products SET publicado = '0' WHERE auto_pub = ".$hoje) or die(mysql_error());
}

$db->close();

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

php - How to fix this error "mysql_fetch_assoc() expects parameter 1 t...

php mysql
Rectangle 27 2

You forgot to check whether $num_results is a MySQL result resource. In this case your query errored, so it's FALSE instead.

mysql_query

php - mysql_num_rows() expects parameter 1 to be resource, boolean giv...

php
Rectangle 27 3

$username
$sql = "SELECT * FROM `apps` WHERE `MCName` = '". $username . "'";

@user1528331 Common typo, happens to the best of us! =P

@Baba ... Not to add fuel to your fire - but 1) The OP's question didn't ask anything regarding SQLi; should I be downvoted for not recommending it (he correctly uses mysql_real_escape_string() above, so he knows about it). 2) The OP already uses the old mysql_ methods - should I be downvoted for answering his question and not telling him to restructure his entire application? 3) Misleading.. can't argue, don't know how you interpret it. Hop off your high-horse and learn to take critism =] (oh yeah, and I didn't downvote you - I just commented)

@IliaRostovtsev Not to extend the discussion, but yes - using mysql_real_escape_string() to santize numeric input that is not wrapped in quotes is useless.

php - Warning: mysql_num_rows() expects parameter 1 to be resource, bo...

php mysql
Rectangle 27 1

$db =& DB::connect('mysql://usr:pw@localhost/dbname');
if (PEAR::isError($db)) {
    die($db->getMessage());
}

then create a resource:

$res =& $db->query("SELECT * FROM `channels` WHERE `cat_slug` = '$cat'");
while ($res->fetchInto($row)) {
    echo $row[0] . "\n";
}

It looks like you were using a mixture of standard PHP and PEAR.

in standard PHP, you'd need to do it like this:

$sql = "SELECT * FROM channels WHERE cat_slug = '$cat'";
$res = mysql_query($sql, $conn) //where $conn is your db link stuff

THEN you could do a fetch array

$sql = dbquery("SELECT * FROM channels WHERE cat_slug = '$cat' ");

php - Warning: mysql_fetch_array() expects parameter 1 to be resource,...

php mysql
Rectangle 27 1

$db =& DB::connect('mysql://usr:pw@localhost/dbname');
if (PEAR::isError($db)) {
    die($db->getMessage());
}

then create a resource:

$res =& $db->query("SELECT * FROM `channels` WHERE `cat_slug` = '$cat'");
while ($res->fetchInto($row)) {
    echo $row[0] . "\n";
}

It looks like you were using a mixture of standard PHP and PEAR.

in standard PHP, you'd need to do it like this:

$sql = "SELECT * FROM channels WHERE cat_slug = '$cat'";
$res = mysql_query($sql, $conn) //where $conn is your db link stuff

THEN you could do a fetch array

$sql = dbquery("SELECT * FROM channels WHERE cat_slug = '$cat' ");

php - Warning: mysql_fetch_array() expects parameter 1 to be resource,...

php mysql
Rectangle 27 1

AND is missing from the query in the WHERE clause

$sql_1=mysql_query("SELECT * FROM category WHERE tier='2'  parent='$p_id' ORDER BY id ASC");
$sql_1=mysql_query("SELECT * FROM category WHERE tier='2' AND parent='$p_id' ORDER BY id ASC");

php - How to fix Warning: mysql_fetch_array() expects parameter 1 to b...

php sql