Функция выглядит вот так
| Код | sub newSection { my $html1=<<HTML1; <FORM action="$DATA{'URL_SITE'}cgi-bin/forum.pl" method="POST"> <INPUT type="submit" name="newSection" value="Новый Раздел" class="newSection"> </FORM> HTML1 my $html2=<<HTML2; <center> <form action="$DATA{'URL_SITE'}cgi-bin/forum.pl" method="POST"> <table> <tr> <td>Название</td> <td><input type="text" name="nameSection" maxlength="16" placeholder="введите название" class="nameSection"></td> </tr><tr> <td>Позиция</td> <td><input type="text" name="sectionPosition" maxlength="10" placeholder="введите позицию" class="sectionPosition"></td> </tr><tr> <td><input type="submit" name="createSection" value="Создать" class="createSection"></td> <td><a href="$DATA{'URL_SITE'}cgi-bin/forum.pl" class="newSection">Отмена</a></td> </tr> </table> </form> </center> HTML2 if (!defined(param("newSection")) and !defined(param("createSection"))) { print $html1; } elsif (defined(param("newSection"))) { print "<center><b>Новый раздел:</b></center>"; print $html2; } elsif (defined(param("createSection"))) { my $name = param("nameSection"); my $position = param("sectionPosition"); my $ds = 'DBI:mysql:' . $DATA{'DB'} . ':' . $DATA{'PASSW'}; my $db = DBI->connect($ds, $DATA{'USER'}, $DATA{'PASSW'}); if (!$db) { print "$DATA{'C-T'}"; print "Ошибка соеденения с БД"; exit(); } $db->do("SET NAMES utf8"); my $checkSection = $db->prepare("SELECT id_section FROM section WHERE name='$name'"); $checkSection->execute() or die $db->errstr; if ($checkSection->err) { print "$DATA{'C-T'}"; print "1 Ошибка выборки из БД"; exit(); } if ($checkSection->rows() == 1) { print "<b>Раздел с таким названием уже существует!</b>"; print $html2; $checkSection->finish(); $db->disconnect(); } else { $db->do("INSERT INTO section (name, position) VALUES ('$name', $position)"); $db->do("INSERT INTO section_access (id_status) VALUES (1)"); print "<center><b></b>Раздел успешно создан!</b></center>"; $checkSection->finish(); $db->disconnect(); } } }
|
|