PHP:
скопировать код в буфер обмена
скопировать код в буфер обмена
- <h2 align="center">Оформление заказа</h2>
- <?
- {
- ?>
- <form action="index.php?view=order" method="post" id="cart-form">
- <table id="mycart" align="center" cellspacing="0" cellpadding="0" border="0">
- <tr>
- <th>Товар</th>
- <th>Цена</th>
- <th>Кол-во</th>
- <th>Всего</th>
- </tr>
- <? foreach($_SESSION['cart'] as $id => $quantity):
- $product = get_product($id);
- ?>
- <tr>
- <td align="center"><?=$product['title'];?></td>
- <td align="center"><?=$quantity;?></td>
- </tr>
- <?endforeach;?>
- </table>
- <p class="total" align="center">Общая сумма заказа: <span class="product-price"><?=number_format($_SESSION['total_price'],2);?></span></p>
- <p align="center" style="color: black;">
- Ваше Имя: <input type="text" name="name" required/> Ваша Фамилия: <input type="text" name="s_name" required/> Ваш адрес: <input type="text" name="address" required/> Почтовый индекс: <input type="text" name="post_index" required/> Ваш e-mail: <input type="text" name="email" /><br required/>
- </p>
- <p align="center"><input type="submit" name="order" value="Заказать" /></p>
- </form>
- <?
- }
- {
- $pattern_name = '/^[a-zA-Zа-яА-ЯЁё]{1,32}$/u';
- $pattern_index = '/^[0-9]{6}$/u';
- $pattern_email = '/^[\w\.\-]+\@+[a-z]+\.+[a-z]{1,5}$/';
- $pattern_addres = '/^[a-zA-Zа-яА-ЯЁё0-9\s\.]{1,100}$/u';// \s - пробел, точка
- $error = "Некорректно введёна фамилия"; //ошибка
- } else {
- $error = false; //ошибка не найдена
- }
- }
- $error = "Некорректно введно имя";
- } else {
- $error = false;
- }
- }
- $error = "Некорректно введён почтовый индекс" ;
- } else {
- $error = false;
- }
- }
- $error = "Некорректно введён адрес";
- } else {
- $error = false;
- }
- }
- $error = "Некорректно введён email";
- } else {
- $error = false;
- }
- }
- if ($error === false) //Если ошибка не найдена, выполняется код
- {
- foreach($_POST as $ArrKey => $ArrStr)
- {
- $ArrKey = $_POST[$ArrKey];
- }
- 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' style='color: #black;'>Ваш заказ успешно принят! Спасибо за покупку!</p>";
- }
- else
- {
- //Если ошибка есть
- echo "<p align='center' style='color: #black;'>ОШИБКА В ВВЕДЕННЫХ ДАННЫХ</p>";
- }
- }
- ?>
- <?