Здравствуйте! Не работает INSERT INTO, в чем может быть причина? Буду благодарна за любую помощь.
<?
function add_to_cart($id)
{
if(isset($_SESSION['cart'][$id]))
{
$_SESSION['cart'][$id]++;
return true;
}
else
{
$_SESSION['cart'][$id] = 1;
return true;
}
return false;
}
function update_cart()
{
foreach($_SESSION['cart'] as $id => $qty)
{
if($_POST[$id] == '0')
{
unset($_SESSION['cart'][$id]);
}
else
{
$_SESSION['cart'][$id] = $_POST[$id];
}
}
}
function total_items($cart)
{
$num_items = 0;
if(is_array($cart))
{
foreach($cart as $id => $qty)
{
$num_items += $qty;
}
}
return $num_items;
}
function total_price($cart)
{
$total_price = 0.0;
db_connect();
if(is_array($cart))
{
foreach($cart as $id => $qty)
{
$query = "SELECT price FROM products WHERE id='$id'";
$result = mysql_query($query);
if($result)
{
$item_price = mysql_result($result,0,'price');
$total_price += $item_price * $qty;
}
}
}
return $total_price;
} ?>
<? foreach($_SESSION['cart'] as $id => $quantity):
$product = get_product($id);
?>
<tr>
<td align="center"><?=$product['title'];?></td>
<td align="center"><?=number_format($product['price'],2);?> руб.</td>
<td align="center"><input type="text" size="2" name="<?=$id;?>" maxlength="2" value="<?=$quantity;?>" /></td>
<td align="center"><?=number_format($product['price'] * $quantity ,2);?> руб.</td>
</tr>
<? endforeach;?>
<?
}
if($_SESSION['cart'] && isset($_POST['order']))
{
$name = $_POST['name'];
$s_name = $_POST['s_name'];
$address = $_POST['address'];
$post_index = $_POST['post_index'];
$email = $_POST['email'];
$date = date('Y-m-d');
$time = date('H:i:s');
foreach($_SESSION['cart'] as $id => $quantity):
$product = get_product($id);
$query = mysql_query("INSERT INTO orders(name,s_name,address,post_index,email,date,time,product,prod_id,price,qty) VALUES ('$name','$s_name','$address','$post_index','$email','$date','$time','{$product['title']}','{$product['id']}','{$product['price']}','$quantity')");
endforeach;
echo "<p align='center'>Ваш заказ успешно принят! Спасибо за покупку!</p>";
}
?>