Вот 1-файл:
<?php
/*подключение библиотек*/
require "/system/shop_db.inc.php";
require "/system/shop_lib.inc.php";
//if ($author = ' ') { $author = 'off'; }
$author = clearData($_POST['author']);
$title = clearData($_POST['title']);
$categoriy = clearData($_POST['categoriy']);
$sostoyanie = clearData($_POST['sostoyanie']);
$description = clearData($_POST['description']);
//if ($diameter= ' ') { $diameter = 'off'; }
$diameter = clearData($_POST['diameter']);
//if ($gurt= ' ') { $gurt = 'off'; }
$gurt = clearData($_POST['gurt']);
//if ($height)) { $height = 'off'; }
$height = clearData($_POST['height']);
//if ($length)) { $length = 'off'; }
$length = clearData($_POST['length']);
$material = clearData($_POST['material']);
//if ($placeofOrigin)) { $placeofOrigin = 'off'; }
$placeofOrigin = clearData($_POST['placeofOrigin']);
$weight = clearData($_POST['weight']);
//if ($width)) { $width = 'off'; }
$width = clearData($_POST['width']);
//if ($picname)) { $picname = 'off'; }
$picname = clearData($_POST['picname']);
//if ($pubyear)) { $pubyear = 'off'; }
$pubyear = clearData($_POST['pubyear'], "i");
$price = clearData($_POST['price'], "i");
save($author, $title, $categoriy, $sostoyanie, $description, $diameter, $gurt, $height, $length, $material, $placeofOrigin, $weight, $width, $picname, $pubyear, $price);
?>
Файл shop_lib.inc.php:
<?php
/*Сохраняет новый товар в таблицу catalog*/
function save($author, $title, $categoriy, $sostoyanie, $description, $diameter, $gurt, $height, $length, $material, $placeofOrigin, $weight, $width, $picname, $pubyear, $price){
$sql = "INSERT INTO catalog(
author,
title,
categoriy,
sostoyanie,
description,
diameter,
gurt,
height,
length,
material,
placeofOrigin,
weight,
width,
picname,
pubyear,
price
)
VALUES(
".$author.".,
".$title.",
".$categoriy.",
".$sostoyanie.",
".$description.",
".$diameter.",
".$gurt.",
".$height.",
".$length.",
".$material.",
".$placeofOrigin.",
".$weight.",
".$width.",
".$picname.",
".$pubyear.",
".$price."
)";
mysql_query($sql) or die(mysql_error());
}
/*Фильтрация полученных данных*/
function clearData($data, $type = "s"){
switch($type){
case "s":
return mysql_real_escape_string(trim(strip_tags($data))); break;
case "i":
return (int)$data;
/*Для фильтрации данных пользователя, который оформил заказ и эти данные уходят в файл*/
case "string_file": return trim(strip_tags($data));
}
}
?>
Файл shop_lib.inc.php:
<?php
/*Адрес сервера*/
define("DB_HOST", "localhost");
/*Логин для соединения с базой*/
define("DB_LOGIN", "shop");
/*Пароль для соединения с базой*/
define("DB_PASSWORD", "shop");
/*Имя базы данных*/
define("DB_NAME", "shop");
/*Имя файла с личными данными пользователей*/
define("ORDERS_LOG", "orders.log");
/*Количество товаров в корзине пользователя. Изначально ноль*/
$count = 0;
/*Устанавливаем соединение с сервером базы данных*/
mysql_connect(DB_HOST, DB_LOGIN, DB_PASSWORD) or die("Не могу соединиться с сервером базы данных!");
/*Выбираем базу данных*/
mysql_select_db(DB_NAME) or die(mysql_error());
/*При добавлении товаров в корзину, счетчик $count будет меняться, то есть будет меняться количество товаров в корзине*/
$sql = "SELECT count(*) FROM basket WHERE customer='".session_id()."'";
$result = mysql_query($sql) or die(mysql_error());
$count = mysql_result($result, 0, "count(*)");
?>