0

Hello,

I know nothing about PHP and this error has come up and I've been researching for days and have tried just about everything. Hopefully, I've given you enough information, but can you tell me why this line:

$row2  = mysql_fetch_assoc($res); 

is the one called up in the following error?

''Error: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource... ''

function wl_cart_transfer(){

            global $OPTION,$customerArea;

            $table  = is_dbtable_there('wishlist');
            $wid    = (int) trim($_POST['transfer_wl_item']);           //change.9.9
            $qStr   = "SELECT * FROM $table WHERE wid = $wid LIMIT 0,1";
            $res    = mysql_query($qStr);
            $row    = mysql_fetch_assoc($res);

            $extraSQL = $this->attributesExtraSql($row);

            $table  = is_dbtable_there('inventory');
            $itemID = trim($row['item_id']);
            $qStr   = "SELECT amount FROM $table WHERE $extraSQL ID_item = '$itemID' LIMIT 0,1";    
            $res    = mysql_query($qStr);
            $row2   = mysql_fetch_assoc($res);  
            $stock  = (int) $row2['amount'];

            if($OPTION['wps_track_inventory'] == 'not_active'){
                $stock = 100000;
            }
            else {
                $table  = is_dbtable_there('inventory');
                $itemID = trim($row['item_id']);
                $qStr   = "SELECT amount FROM $table WHERE $extraSQL ID_item = '$itemID' LIMIT 0,1";    
                $res    = mysql_query($qStr);
                $row2   = mysql_fetch_assoc($res);  
                $stock  = (int) $row2['amount'];    
            }

Thanks in advance.

Edited by Nick Evan: Fixed formatting

2
Contributors
7
Replies
8
Views
6 Years
Discussion Span
Last Post by diafol
0

> I know nothing about PHP

Perhaps your query is wrong.

I've been playing around with the query and can't seem to find out what's wrong with the statement.

0

The query is MYSQL.
Paste the query into phpmyadmin and see what it gives.

Yes, I've done that and it does pull the query as an error, but I don't know how to fix it...(again, I know nothing, this was code written by someone else and I can't get help there).

qStr = "SELECT amount FROM $table WHERE $extraSQL ID_item = '$itemID' LIMIT 0,1";

MySQL said: Documentation
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '$qStr = "SELECT amount FROM $table WHERE $extraSQL ID_item = '$itemID' LIMIT 0,1' at line 1

Thanks for your responses.

0

SELECT amount FROM $table WHERE $extraSQL ID_item = '$itemID' LIMIT 0,1

would not work in phpmyadmin anyway as it contains php variables (bold).

do this in your php file:

echo "SELECT amount FROM $table WHERE $extraSQL ID_item = '$itemID' LIMIT 0,1";

and see what it gives you.
This is what you paste into your phpmyadmin window. I suspect that one or more of these vars isn't set.
echo "

0

SELECT amount FROM $table WHERE $extraSQL ID_item = '$itemID' LIMIT 0,1

would not work in phpmyadmin anyway as it contains php variables (bold).

do this in your php file:

echo "SELECT amount FROM $table WHERE $extraSQL ID_item = '$itemID' LIMIT 0,1";

and see what it gives you.
This is what you paste into your phpmyadmin window. I suspect that one or more of these vars isn't set.
echo "

Fixed it!...it was this line: $extraSQL = $this->attributesExtraSql($row); it needed to say row2.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.