0

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\dl\cart\includes\functions.php on line 37
There was an error with your order!

function get_order_total(){
            $cnt = array();
                $products = array();

                foreach($_POST as $key=>$value)
                {
                    $key=(int)str_replace('_cnt','',$key);

                    $products[]=$key;
                    $cnt[$key]=$value;
                }

                $result = mysql_query("SELECT * FROM shop WHERE id IN(".join($products,',').")");

                if(!mysql_num_rows($result))
                {
                    echo '<h1>There was an error with your order!</h1>';
                }
                else
                {
                    echo '<h1>You ordered:</h1>';

                    while($row=mysql_fetch_assoc($result))
                    {
                        echo '<h2>'.$cnt[$row['id']].' x '.$row['name'].'</h2>';

                        $total+=$cnt[$row['id']]*$row['price'];
                    }

                    echo '<h1>Total: $'.$total.'</h1>';
                }
2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by Kieran Y5
0

$result = mysql_query("SELECT * FROM shop WHERE id IN(".join($products,',').")");

Something is wrong with your query. I assume your join() function does something... Without knowning what exactly your join() function does, I can't really tell you whats wrong with your query string...

Edit: oops, join is a built in php function. Gona redo this... Im being an idiot

Try this:

$result = mysql_query("SELECT * FROM shop WHERE id IN(".join(',', $products).")");

Join is a alias of implode()
Syntax:
string implode ( string $glue , array $pieces )

You were putting the array first...

Edited by Kieran Y5: Being an idiot

0

Im being an idot

Assuming $res is the mysql resouce from:

$res = mysql_connect(DB_HOST, BE_USER, DB_PASS);
mysql_select_db(DB_NAME, $res);

At the top of the function put:

global $res;

And then do

$result = mysql_query("SELECT * FROM `shop` WHERE `id` IN(".join($products,',').")", $res);

If that doesn't work, then I give up with PHP... I can't think of any other reason it wouldn't work...

Edited by Kieran Y5

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.