$conn=mysql教程_connect("localhost","phpdb","phpdb")
or die("不能连接数据库服务器: ".mysql_error());
mysql_select_db("product",$conn) or die ("不能选择数据库: ".mysql_error());
?>
数据库结构:
product.sql
drop database if exists product;
create database product;
use product;
CREATE TABLE user (
id int(3) NOT NULL auto_increment,
name varchar(20) not null,
password varchar(50) NOT NULL,
tel varchar(20),
regtime datetime not null,
PRIMARY KEY (id)
);
CREATE TABLE company (
id int(6) not null auto_increment,
name varchar(100) NOT NULL,
address varchar(255) NOT NULL,
tel varchar(100) NOT NULL,
product varchar(255),
linkman varchar(100) NOT NULL,
addtime datetime NOT NULL,
PRIMARY KEY (id)
);
create table product (
productid int(6) not null auto_increment,
companyid int(6) not null,
name varchar(50) not null,
brand varchar(50) not null,
type varchar(50) not null,
introduction text,
other text,
primary key (productid)
);
CREATE TABLE buylog(
id int(6) NOT NULL auto_increment,
user varchar(20) not null,
productid int(6) not null,
amount int(6) not null,
buyprice decimal(9,2) DEFAULT '0.00' NOT NULL,
cost decimal(9,2) DEFAULT '0.00' NOT NULL,
ip varchar(20),
buytime datetime NOT NULL,
other text,
primary KEY (id)
);
create table stock (
productid int(6) not null,
amount int(6) not null,
buyprice decimal(9,2) DEFAULT '0.00' NOT NULL,
sellprice decimal(9,2) DEFAULT '0.00' NOT NULL,
cost decimal(9,2) DEFAULT '0.00' NOT NULL,
introduction text,
buytime datetime not null,
other text,
primary key(productid, buyprice)
);
CREATE TABLE selllog(
id int(10) NOT NULL auto_increment,
user varchar(20) not null,
productid int(6) not null,
amount int(6) not null,
buyprice decimal(9,2) DEFAULT '0.00' NOT NULL,
sellprice decimal(9,2) DEFAULT '0.00' NOT NULL,
cost decimal(9,2) DEFAULT '0.00' NOT NULL,
sellmoney decimal(9,2) DEFAULT '0.00' NOT NULL,
ip varchar(20),
buytime datetime NOT NULL,
selltime datetime not null,
other text,
primary KEY (id)
);
// 连接数据库,注册用户
$sql="insert into user(name,password, tel, regtime) values('$name','$password','$tel','$now')";
mysql_query($sql,$conn) or die ("注册用户失败: ".mysql_error());
";
exit();
}
// 如果是添加新记录
if ($reg){
$result = mysql_query("SELECT * FROM company WHERE name='$name'",$conn);
$userrow=mysql_fetch_array($result);
if (!empty($userrow)) {
echo "
";
exit();
}
// 如果是添加新记录
if ($reg){
$result = mysql_query("SELECT * FROM product WHERE name='$name' and companyid='$old_id' and brand='$brand' and type='$type'",$conn);
$userrow=mysql_fetch_array($result);
if (!empty($userrow)) {
echo "
该公司的相同产品记录已经存在!
";
exit();
}
$query = "insert into product(companyid, name, brand, type, introduction, other) values ('$old_id','$name','$brand', '$type', '$intro', '$other')";
$res = mysql_query($query, $conn) or die("添加产品记录失败: ".mysql_error());
}
elseif ($mod){
$query = "insert into product(companyid, name, brand, type, introduction, other) values ('$old_id','$name','$brand', '$type', '$intro', '$other')";
$query = "update product set name='$name',brand='$brand', type='$type', introduction='$intro', other='$other' where productid='$old_pid'";
$res = mysql_query($query, $conn) or die("修改产品记录失败: ".mysql_error());
}
?>