|
|
|
| Не могу понять в чем дело, из скрипта не добавляются данные в БД
Простите, что привожу текст полностью, но так, мне кажется картина будет ясна
Схема данных
create database prepod;
use prepod;
create table teacher
(
teacher_key int unsigned not null auto_increment primary key,
fname char(20) not null,
name char(20) not null,
sname char(25) not null,
bdate date not null,
ulogon char(13) not null,
upass char(8) not null,
uexp char(4) not null,
ustepen1 char(9) not null,
ustepen2 char(20) not null,
uzvan1 char(20) not null,
uzvan2 char(8) not null,
udolzn char(20) not null
);
create table icq
(
teacher_key int unsigned not null references teacher(teacher_key),
icq char(10),
primary key (teacher_key, icq)
)type=InnoDB;
create table work1
(
teacher_key int unsigned not null references teacher(teacher_key),
work1 char(180),
izd1 char(50),
iyear1 char(4),
primary key (teacher_key)
)type=InnoDB;
create table work2
(
teacher_key int unsigned not null references teacher(teacher_key),
work2 char(180),
izd2 char(50),
iyear2 char(4),
primary key(teacher_key)
)type=InnoDB;
create table work3
(
teacher_key int unsigned not null references teacher(teacher_key),
work3 char(180),
izd3 char(50),
iyear3 char(4),
primary key(teacher_key)
)type=InnoDB;
create table work4
(
teacher_key int unsigned not null references teacher(teacher_key),
work4 char(180),
izd4 char(50),
iyear4 char(4),
primary key(teacher_key)
)type=InnoDB;
create table work5
(
teacher_key int unsigned not null references teacher(teacher_key),
work5 char(180),
izd5 char(50),
iyear5 char(4),
primary key(teacher_key)
)type=InnoDB;
create table kaf
(
teacher_key int unsigned not null references teacher(teacher_key),
kname char(150),
primary key(teacher_key)
)type=InnoDB;
create table emails1
(
teacher_key int unsigned not null references teacher(teacher_key),
email1 char(60),
primary key(teacher_key)
)type=InnoDB;
create table emails2
(
teacher_key int unsigned not null references teacher(teacher_key),
email2 char(60),
primary key(teacher_key)
)type=InnoDB;
create table cours1
(
teacher_key int unsigned not null references teacher(teacher_key),
ncourse1 char(200),
ctype1 char(15),
primary key(teacher_key)
)type=InnoDB;
create table cours2
(
teacher_key int unsigned not null references teacher(teacher_key),
ncourse2 char(200),
ctype2 char(15),
primary key(teacher_key)
)type=InnoDB;
create table cours3
(
teacher_key int unsigned not null references teacher(teacher_key),
ncourse3 char(200),
ctype3 char(15),
primary key(teacher_key)
)type=InnoDB;
create table cours4
(
teacher_key int unsigned not null references teacher(teacher_key),
ncourse4 char(200),
ctype4 char(15),
primary key(teacher_key)
)type=InnoDB;
create table cours5
(
teacher_key int unsigned not null references teacher(teacher_key),
ncourse5 char(200),
ctype5 char(15),
primary key(teacher_key)
)type=InnoDB;
create table ninterests1
(
teacher_key int unsigned not null references teacher(teacher_key),
ninterest1 char(200),
primary key(teacher_key)
)type=InnoDB;
create table ninterests2
(
teacher_key int unsigned not null references teacher(teacher_key),
ninterest2 char(200),
primary key(teacher_key)
)type=InnoDB;
create table ninterests3
(
teacher_key int unsigned not null references teacher(teacher_key),
ninterest3 char(200),
primary key(teacher_key)
)type=InnoDB;
create table ninterests4
(
teacher_key int unsigned not null references teacher(teacher_key),
ninterest4 char(200),
primary key(teacher_key)
)type=InnoDB;
create table graduation1
(
teacher_key int unsigned not null references teacher(teacher_key),
ugrad1 char(200),
spec1 char(100),
years1 char(4),
yearf1 char(4),
primary key(teacher_key)
)type=InnoDB;
create table graduation2
(
teacher_key int unsigned not null references teacher(teacher_key),
ugrad2 char(200),
spec2 char(100),
years2 char(4),
yearf2 char(4),
primary key(teacher_key)
)type=InnoDB;
create table hobbies1
(
teacher_key int unsigned not null references teacher(teacher_key),
hname1 char(200),
primary key(teacher_key)
)type=InnoDB;
create table hobbies2
(
teacher_key int unsigned not null references teacher(teacher_key),
hname2 char(200),
primary key(teacher_key)
)type=InnoDB;
|
не прходят запросы
<?php ...
//table teacher
$query_teacher = "insert into teacher (teacher_key, fname, name, sname, ulogon, upass, uexp, ustepen1, ustepen2, uzvan1, uzvan2, udolzn)
values (NULL, '".$fname."', '".$name."','".$sname."', '".$ulogon."', '".$upass."', '".$uexp."', '".$ustepen1."', '".$ustepen2."', '".$uzvan1."', '".$uzvan2."', '".$udolzn."')";
//tables works[1-5]
$query_works1 = "insert into work1 (work1, izd1, iyear1)
values ('".$work1."', '".$izd1."', '".$iyear1."')";
$query_works2 = "insert into work2 (work2, izd2, iyear2)
values ('".$work2."','".$izd2."', '".$iyear2."')";
$query_works3 = "insert into work3 (work3, izd3, iyear3)
values ('".$work3."','".$izd3."', '".$iyear3."')";
$query_works4 = "insert into work4 (work4, izd4, iyear4)
values ('".$work4."','".$izd4."', '".$iyear4."')";
$query_works5 = "insert into work5 (work5, izd5, iyear5)
values ('".$work5."','".$izd5."', '".$iyear5."')";
//table icq
$query_icq = "insert into icq (teacher_key, icq)
values (NULL,'".$icq."')";
//table kaf
$query_kaf = "insert into kaf (teacher_key, kname)
values (NULL,'".$kname."')";
//tables emails[1-2]
$query_email1 = "insert into emails1 (teacher_key, email1)
values (NULL,'".$email1."')";
$query_email2 = "insert into emails2 (teacher_key, email2)
values (NULL,'".$email2."'";
//tables courses[1-5]
$query_courses1 = "insert into cours1 (teacher_key, ncourse1, ctype1)
values (NULL,'".$ncourse1."','".$ctype1."')";
$query_courses2 = "insert into cours2 (teacher_key, ncourse2, ctype2)
values (NULL,'".$ncourse2."','".$ctype2."')";
$query_courses3 = "insert into cours3 (teacher_key, ncourse3, ctype3)
values (NULL,'".$ncourse3."','".$ctype3."')";
$query_courses4 = "insert into cours4 (teacher_key, ncourse4, ctype4)
values (NULL,'".$ncourse4."','".$ctype4."')";
$query_courses5 = "insert into cours5 (teacher_key, ncourse5, ctype5)
values (NULL,'".$ncourse5."','".$ctype5."')";
//tables interests[1-4]
$query_interests1 = "insert into inrerests1 (teacher_key, ninterest1)
values (NULL,'".$ninterest1."')";
$query_interests2 = "insert into inrerests2 (teacher_key, ninterest2)
values (NULL,'".$ninterest2."')";
$query_interests3 = "insert into inrerests3 (teacher_key, ninterest3)
values (NULL,'".$ninterest3."')";
$query_interests4 = "insert into inrerests4 (teacher_key, ninterest4)
values (NULL,'".$ninterest4."')";
//tables graduation[1-2]
$query_graduation1 = "insert into graduation1 (teacher_key, ugrad1, spec1, years1, yearf1)
values(NULL,'".$ugrad1."', '".$spec1."', '".$years1."','".$yearf1."')";
$query_graduation2 = "insert into graduation2 (teacher_key, ugrad2, spec2, years2, yearf2)
values(NULL,'".$ugrad2."', '".$spec2."', '".$years2."','".$yearf2."')";
//tables hobbies[1-2]
$query_hobbies1 = "insert into hobbies1 (teacher_key, hname1)
values (NULL,'".$hname1."')";
$query_hobbies2 = "insert into hobbies2 (teacher_key, hname2)
values (NULL,'".$hname2."')";
// Inserting all Queries into Database
///////// Делаю запрос и обработку ошибки:
$result1 = mysql_query($query_teacher);
if (!$result1)
{
echo "ERROR! No data added <br />";
}
else
{
echo "Operation complete sucessifully",mysql_affected_rows();
}
...итд с каждым добавлением
... ?>
|
В итоге выводит
ERROR! No data added
,,,,все 23 раза
В чем дело, наверное что то с запросом, но ЧТО? | |
|
|
|
|
|
|
|
для: Головин Евгений
(08.02.2006 в 05:03)
| | я думаю что косяк скорее всего вот в чём вы вводите:
$query_interests1 = "insert into inrerests1 (teacher_key, ninterest1)
values (NULL,'".$ninterest1."')";
|
а если мне не изменяет память то надо делать примерно так:
$query_interests1 = "insert into inrerests1 values (NULL,'".$ninterest1."')";
|
остальное по аналогии, но могу чтото путать... ну да точно вот оно.. не надо говорить базе куда писать - она сама знает | |
|
|
|
|
|
|
|
для: 10100100
(08.02.2006 в 11:32)
| | всё равно лепит ERROR! No data added...
целый день эту форму делал...жесть( | |
|
|
|
|
|
|
|
для: Головин Евгений
(08.02.2006 в 05:03)
| | Такие здоровые скрипты лучше прикреплять к сообщению в виде архива. | |
|
|
|
|
|
|
|
для: cheops
(08.02.2006 в 14:30)
| | Да я это понял когда опубликовал уже :((
Мне казалось что он меньше)
Cheops, не подскажете ли, в чем косяк? | |
|
|
|
|
|
|
|
для: Головин Евгений
(08.02.2006 в 05:03)
| | введите эту строку
после этой
$result1 = mysql_query($query_teacher);
|
и скажите что пишет браузер! | |
|
|
|
|
|
|
|
для: 10100100
(08.02.2006 в 15:38)
| | Ясно тут 2 косяка
1)
Field 'bdate' doesn't have a default valueERROR! No data added
потому что дата у меня компонуется из 3ех чисел, видимо так нельзя...
$str = "{$byear}-{$bmonth}-{$bnumber}";
|
2)
А остальные из за teacher_key : ему походу не нравится что я туда NULL заталкиваю
А, ЧТО же тогда туда толкать как не NULL, ведь я их внешними ключами к таблице teacher сделал?
Field 'teacher_key' doesn't have a default valueERROR! No data added
|
| |
|
|
|
|
|
|
|
для: Головин Евгений
(08.02.2006 в 15:56)
| | ну - по первому пункту могу сказать что дату можно генирировать и другими способами.
а вот по второму - это не ко мне... | |
|
|
|
|
|
|
|
для: 10100100
(08.02.2006 в 16:28)
| | С датой я разобрался и теперь принемает.
а вот что лепить во внешний ключ?
По идее он должен принемать значения из основной таблицы teacher -> teacher_key
но что туда писать надо при запросе на добавление? NULL - не принемает ((
-----
Напишите пожалуйста запрос на доб. для таблицы такого типа... | |
|
|
|
|
|
|
|
для: Головин Евгений
(08.02.2006 в 17:28)
| | а Вы можете выписать снова но уже отдельно дамп базы и запрос, а то я в этой блин схеме запутался :))) тогда и попробуем что с этим можно сделать :) | |
|
|
|
|
 18.6 Кб |
|
|
для: 10100100
(08.02.2006 в 17:46)
| | вот полностью привожу все коды
PHP
MySQL | |
|
|
|
|
|
|
|
для: Головин Евгений
(08.02.2006 в 17:56)
| | пожалуйста сделайте как я Вас просил выше. я не могу разобраться в Вашем коде... :) | |
|
|
|
|
|
|
|
для: 10100100
(08.02.2006 в 18:11)
| | Всё, я разобрался, спасибо тем не менее, если кому интересно то вот итог кода MySQL:
create table teacher
(
teacher_key int unsigned not null auto_increment primary key,
fname char(25) not null,
name char(25) not null,
sname char(25) not null,
bdate char(10) not null,
ulogon char(15) not null,
upass char(15) not null,
uexp char(4) not null,
ustepen1 char(10) not null,
ustepen2 char(25) not null,
uzvan1 char(25) not null,
uzvan2 char(10) not null,
udolzn char(25) not null
);
create table icq
(
teacher_key int unsigned not null auto_increment references teacher(teacher_key),
icq char(10),
primary key (teacher_key, icq)
)type=InnoDB;
create table work1
(
teacher_key int unsigned not null auto_increment references teacher(teacher_key),
work1 char(180),
izd1 char(50),
iyear1 char(4),
primary key (teacher_key)
)type=InnoDB;
|
Дело в том что я забыл ставить auto_increment !!!! отсюда и "дыры" были!
:))) | |
|
|
|
|
|
|
|
для: Головин Евгений
(09.02.2006 в 01:56)
| | о - ну в принципе вполне логично :))
удачи Вам! | |
|
|
|
|