/    Sign up×
Community /Pin to ProfileBookmark

Parse error: Warning: mysql_fetch_object(): supplied argument is not a valid MySQL…

I’m receiving this error:

[code=php]Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource
[/code]

on the second to last line of this code:

[code=php]$sql = “SELECT l.id lid, l.have, l.qty, if (v.price !=”, v.price, p.price) price, p.name, if (v.sku !=”, v.sku, p.sku) sku, p.id, l.vid, v.name var
FROM list_items l, inv_products p
LEFT JOIN inv_variations v ON v.vid = l.vid AND v.product = l.product
WHERE list=”${_GET[‘id’]}” AND p.id = l.product”;
$r = mysql_query($sql);
while ($p = mysql_fetch_object($r)) {
$i = $i ? 0 : 1;
?>[/code]

When I turn on error detection, I get a T_ENCAPSED_AND_WHITESPACE error.

This code seemed to be working fine before we migrated to a new server a few weeks ago. Our old server was running an outdated version of PHP (4.x?) and I think maybe that’s the cause here. Perhaps some bad syntax that I’m just having no luck finding? Any suggestions are appreciated!

Jack

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@NogDogAug 22.2011 — The "supplied argument..." error means MySQL was not able to process your query, and therefore mysql_query() returned false instead of a query result resource. As such, it's always a good idea to add some defensive code that checks to make sure the result of mysql_query() is not false before trying to do the fetching.

My guess is it's due to the use of double quotes within the SQL itself: I believe they are only allowed around string literals in MySQL if an optional configuration directive is set. Therefore, it's safer to always use single quotes around string values within your SQL statement.

On a side note, directly using a $_GET value within your query is a security hole, as a malicious user can potentially set it to something you would prefer never got sent as part of a DB query. You should be filtering it via mysql_real_escape_string() before using it as a string literal in your query.
×

Success!

Help @jacksaturn spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...