// Отправка письма
function sendMail($options) {
$headers = "Content-type: text/html; charset=utf-8 \r\n";
$headers .= 'From: =?utf-8?B?' . base64_encode($options['fromName']) . '?=<' . $options['fromEmail'] . '>';
return mail($options['toEmail'], $options['subject'], $options['body'], $headers);
}
function addOrderList($data,$conn) {
$cart = json_decode($data['cart'], true);
foreach($cart as $id =>$value ) {
$result = mysqli_query($conn,"SELECT `count` FROM `list` WHERE `id`='$id'") or die (mysqli_error());
$row=mysqli_fetch_row($result);
$row=(int)$row[0];
$result=$row-$cart[$id]['count'];
if ($result<0){$result=0;};
mysqli_query($conn,"UPDATE `list` SET `count`='{$result}' WHERE `id`='$id'") or die (mysqli_error());
var_dump($result);
}
}
function addOrderList($data,$conn) {
$cart = json_decode($data['cart'], true);
foreach($cart as $id =>$value ) {
$resault=mysqli_query($conn,"SELECT 'count' FROM `list` WHERE `id`='$id'") or die(mysqli_error());
$resault=$resault-$cart[$id]['count'];
echo ($resault);
}
}
function addOrder($data,$conn) {
$cart = json_decode($data['cart'], true);
$values = array();
foreach($cart as $id =>$value ) {
$value = sprintf(
"('%s','%s',%d,%d)",
$id,
mysqli_real_escape_string($conn,$cart[$id]['goodname']),
$cart[$id]['goodprice'],
$cart[$id]['count']
);
array_push($values, $value);
}
$values = implode(";", $values);
$values = mysqli_real_escape_string($conn, $values);
$query = sprintf(
"insert into orders2020 (`surname`, `name`, `fathername`, `cart`) values ('%s','%s','%s','%s')",
$data['surname'],
$data['name'],
$data['fathername'],
$values
);
$conn->query($query);