I'm trying to compare the content of 2 arrays, basically I'm using a shopping cart and I need to check the prices of submitted forms against a database, the problem is when I have one incorrect price in the shopping cart it gives me an error message but when I have 1 correct price and 1 incorrect it continues with the checkout, I don't know what I'm doing wrong any help would be appreciated.
foreach ($cart->get_contents() as $item)
{
$item_id = $item['id'];
$item_name = $item['name'];
$item_price = $item['price'];
$item_qty = $item['qty'];
$connection = mysql_connect($dbhost,$dbuser,$dbpass) or die("Error connecting to mysql");
mysql_select_db($dbname);
$query = "select * from products where product_name = '$item_name'";
$result = mysql_query($query);
if (!$result) {
echo mysql_error();
}
while ($row = mysql_fetch_assoc($result)) {
$sql_price[] = $row['product_price'];
$qty[] = $row['product_qty'];
$name = $row['product_name'];
}
foreach($sql_price as $price) {
$price = $price;
if ($price !== $item_price) {
$valid_prices = false;
}else{
$valid_prices = true;
}
}
}
if ($valid_prices !== true)
{
// KILL THE SCRIPT
die($jcart['text']['checkout_error']);
}