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>';
                }

Recommended Answers

All 2 Replies

$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...

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...

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.